Skip to content

Commit

Permalink
Merge pull request #13 from thejoshualewis/master
Browse files Browse the repository at this point in the history
IPN Order Mapping
  • Loading branch information
thejoshualewis committed Jun 17, 2019
2 parents 29c2b3b + b17ce02 commit d935884
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
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

0 comments on commit d935884

Please sign in to comment.