Skip to content

Commit

Permalink
Added IPN updates
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoshualewis committed Apr 9, 2021
1 parent 37b1b29 commit e644c8c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
19 changes: 10 additions & 9 deletions code/Bitpay/BPCheckout/Model/IpnManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ public function BPC_Invoice($item){
return $item;
}

public function BPC_checkInvoiceStatus($orderID,$item)
public function BPC_checkInvoiceStatus($orderID,$item,$token)
{
$post_fields = ($item->item_params);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://' . $item->invoice_endpoint . '/invoices/' . $post_fields->invoiceID);
curl_setopt($ch, CURLOPT_URL, 'https://' . $item->invoice_endpoint . '/invoices/' . $post_fields->invoiceID.'?token='.$token);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
Expand Down Expand Up @@ -225,7 +225,8 @@ public function postIpn()
$item = $this->BPC_Item( $config,$params);

$invoice = $this->BPC_Invoice($item);
$orderStatus = json_decode($this->BPC_checkInvoiceStatus($order_invoice,$item));
$orderStatus = json_decode($this->BPC_checkInvoiceStatus($order_invoice,$item,$bitpay_token));

$invoice_status = $orderStatus->data->status;


Expand All @@ -242,7 +243,7 @@ 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->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->invoice_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);
Expand All @@ -253,7 +254,7 @@ public function postIpn()
case 'invoice_confirmed':
#pending or processing from plugin settings
if ($invoice_status == 'confirmed'):
$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> processing has been completed.');
$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->invoice_endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> processing has been completed.');
if ($bitpay_ipn_mapping != 'processing'):
#$order->setState(Order::STATE_NEW)->setStatus(Order::STATE_NEW);
$order->setState('new', true);
Expand All @@ -270,7 +271,7 @@ 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->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->invoice_endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> is processing.');
$order->setState('new', true);
$order->setStatus('pending', true);
$order->save();
Expand All @@ -280,15 +281,15 @@ public function postIpn()

case 'invoice_failedToConfirm':
if ($invoice_status == 'invalid'):
$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->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->invoice_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->save();
return true;
endif;
break;

case 'invoice_expired':
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->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->invoice_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;
Expand Down Expand Up @@ -330,6 +331,6 @@ public function createMGInvoice($order)
}
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_3.14.2002';
return 'Bitpay_BPCheckout_Magento2_4.09.2102';
}
}
2 changes: 1 addition & 1 deletion code/Bitpay/BPCheckout/Observer/BPRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
} //end execute function
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_3.14.2002';
return 'Bitpay_BPCheckout_Magento2_4.09.2102';

}

Expand Down
4 changes: 2 additions & 2 deletions code/Bitpay/BPCheckout/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "",
"type": "magento2-module",
"license": "mit",
"version":"3.14.2002",
"version":"4.09.2102",
"authors": [
{
"email": "[email protected]",
Expand All @@ -12,7 +12,7 @@
],
"minimum-stability": "dev",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0|~7.2.0"
"php": "~7.3.0"
},
"autoload": {
"files": [
Expand Down

0 comments on commit e644c8c

Please sign in to comment.