Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPN Order Mapping #13

Merged
merged 1 commit into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions code/Bitpay/BPCheckout/Model/Config/Source/Ipn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Bitpay\BPCheckout\Model\Config\Source;


/**
* IPN Model
*/
class Ipn implements \Magento\Framework\Option\ArrayInterface
{

public function toOptionArray()
{
return [
'pending' => 'Pending Payment',
'processing' => 'Processing',
];

}
}
30 changes: 22 additions & 8 deletions code/Bitpay/BPCheckout/Model/IpnManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function postIpn()

#is it in the lookup table
$sql = "SELECT * FROM $table_name WHERE order_id = '$orderid' AND transaction_id = '$order_invoice' ";

$result = $connection->query($sql);
$row = $result->fetch();
if ($row):
Expand All @@ -77,13 +76,13 @@ public function postIpn()
if ($env == 'prod'):
$bitpay_token = $this->getStoreConfig('payment/bpcheckout/bitpay_prodtoken');
endif;
$bitpay_ipn_mapping = $this->getStoreConfig('payment/bpcheckout/bitpay_ipn_mapping');

$config = (new \Bitpay\BPCheckout\BitPayLib\BPC_Configuration($bitpay_token, $env));
$params = (new \stdClass());

$params->invoiceID = $order_invoice;
$params->extension_version = $this->getExtensionVersion();

$item = (new \Bitpay\BPCheckout\BitPayLib\BPC_Item($config, $params));
$invoice = (new \Bitpay\BPCheckout\BitPayLib\BPC_Invoice($item));

Expand All @@ -95,19 +94,35 @@ public function postIpn()

$order = $this->getOrder($orderid);
#now update the order

switch ($event['name']) {
case 'invoice_confirmed':

case 'invoice_completed':

$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> status has changed to Completed.');
$order->save();
return true;
break;

case 'invoice_confirmed':
#pending or pcoressing from plugin settings

$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> processing has been completed.');
$order->setState(Order::STATE_COMPLETE)->setStatus(Order::STATE_COMPLETE);
if($bitpay_ipn_mapping != 'processing'):
$order->setState(Order::STATE_PENDING_PAYMENT)->setStatus(Order::STATE_PENDING_PAYMENT);
else:
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
endif;


$order->save();
return true;
break;

case 'invoice_paidInFull':

#STATE_PENDING
$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> is processing.');
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
$order->setState(Order::STATE_PENDING_PAYMENT)->setStatus(Order::STATE_PENDING_PAYMENT);
$order->save();
return true;

Expand All @@ -116,7 +131,6 @@ public function postIpn()
case 'invoice_failedToConfirm':

$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> has become invalid because of network congestion. Order will automatically update when the status changes.');
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
$order->save();
return true;
break;
Expand All @@ -143,6 +157,6 @@ public function postIpn()
}
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_3.0.0.1';
return 'Bitpay_BPCheckout_Magento2_3.0.0.2';
}
}
2 changes: 1 addition & 1 deletion code/Bitpay/BPCheckout/Observer/BPRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
} //end execute function
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_3.0.0.1';
return 'Bitpay_BPCheckout_Magento2_3.0.0.2';

}

Expand Down
5 changes: 5 additions & 0 deletions code/Bitpay/BPCheckout/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
<source_model>Bitpay\BPCheckout\Model\Config\Source\Environment</source_model>
</field>

<field id="bitpay_ipn_mapping" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Status mapping - BitPay invoice / Magento order</label>
<comment><![CDATA[Map the BitPay “confirmed” invoice status to the preferred Magento order status, based on the transaction speed you have selected in your BitPay <a target = "_blank" href = "https://bitpay.com/dashboard/settings/edit/order">dashboard</a>]]></comment>
<source_model>Bitpay\BPCheckout\Model\Config\Source\Ipn</source_model>
</field>

<field id="bitpay_ux" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Checkout Flow </label>
Expand Down