Skip to content

Commit

Permalink
added order mapping to Refund IPN
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoshualewis committed Feb 17, 2021
1 parent 1b3641c commit 37b1b29
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
23 changes: 23 additions & 0 deletions code/Bitpay/BPCheckout/Model/Config/Source/Refundstatus.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;

/**
*Refund Status Model
*/
class Refundstatus implements \Magento\Framework\Option\ArrayInterface
{

public function toOptionArray()
{

return [
['value' => 'closed', 'label' => __('True')],
['value' => 'ignore', 'label' => __('False')]
];

}
}
14 changes: 4 additions & 10 deletions code/Bitpay/BPCheckout/Model/IpnManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public function postIpn()
endif;

$bitpay_ipn_mapping = $this->getStoreConfig('payment/bpcheckout/bitpay_ipn_mapping');
$bitpay_refund_mapping = $this->getStoreConfig('payment/bpcheckout/bitpay_refund_mapping');

$config = $this->BPC_Configuration($bitpay_token,$env);

Expand Down Expand Up @@ -241,13 +242,10 @@ public function postIpn()

case 'invoice_completed':
if ($invoice_status == 'complete'):

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

$this->createMGInvoice($order);

return true;
endif;
break;
Expand All @@ -264,7 +262,6 @@ public function postIpn()
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
$this->createMGInvoice($order);
endif;

$order->save();
return true;
endif;
Expand All @@ -273,7 +270,6 @@ public function postIpn()
case 'invoice_paidInFull':
#STATE_PENDING
if ($invoice_status == 'paid'):

$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> is processing.');
$order->setState('new', true);
$order->setStatus('pending', true);
Expand All @@ -294,20 +290,18 @@ public function postIpn()
if ($invoice_status == 'expired'):
$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> has expired.');
$order->setState(Order::STATE_CANCELED)->setStatus(Order::STATE_CANCELED);

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

case 'invoice_refundComplete':
#load the order to update

$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> has been refunded.');
$order->setState(Order::STATE_CLOSED)->setStatus(Order::STATE_CLOSED);

if($bitpay_refund_mapping == "closed"):
$order->setState(Order::STATE_CLOSED)->setStatus(Order::STATE_CLOSED);
endif;
$order->save();

return true;
break;
}
Expand Down
6 changes: 6 additions & 0 deletions code/Bitpay/BPCheckout/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
<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_refund_mapping" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Status mapping - BitPay invoice / Magento order on BitPay Refunds</label>
<comment><![CDATA[If set to TRUE, Magento will set the Order State to Closed. If set to FALSE, no changes will be made to the Magento order]]></comment>
<source_model>Bitpay\BPCheckout\Model\Config\Source\Refundstatus</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
2 changes: 1 addition & 1 deletion code/Bitpay/BPCheckout/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Bitpay_BPCheckout" setup_version="3.5.2001"></module>
<module name="Bitpay_BPCheckout" setup_version="3.6.2102"></module>
</config>

0 comments on commit 37b1b29

Please sign in to comment.