Skip to content

Commit

Permalink
added configuration for custom redirect url
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoshualewis committed May 18, 2021
1 parent c59164b commit a947653
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 14 deletions.
23 changes: 23 additions & 0 deletions code/Bitpay/BPCheckout/Model/Config/Source/Cancelstatus.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 Cancelstatus implements \Magento\Framework\Option\ArrayInterface
{

public function toOptionArray()
{

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

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

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


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

Expand Down Expand Up @@ -290,7 +292,9 @@ public function postIpn()
case 'invoice_expired':
if ($invoice_status == '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);
if($bitpay_cancel_mapping == "cancel"):
$order->setState(Order::STATE_CANCELED)->setStatus(Order::STATE_CANCELED);
endif;
$order->save();
return true;
endif;
Expand Down Expand Up @@ -331,6 +335,6 @@ public function createMGInvoice($order)
}
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_4.09.2102';
return 'Bitpay_BPCheckout_Magento2_5.01.2102';
}
}
26 changes: 17 additions & 9 deletions code/Bitpay/BPCheckout/Observer/BPRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$modal = true;
endif;

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

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

//create an item, should be passed as an object'
Expand Down Expand Up @@ -276,33 +278,39 @@ public function execute(\Magento\Framework\Event\Observer $observer)
#leave alone
if ($modal == false):
#this will send them back to the order/returns page to lookup
$params->redirectURL = $this->getBaseUrl() . 'sales/guest/form';
if(isset($bitpay_redirect_url)):
$params->redirectURL = $bitpay_redirect_url;
else:
$params->redirectURL = $this->getBaseUrl() . 'sales/guest/form';
endif;
#set some info for guest checkout
setcookie('oar_order_id', $order_id_long, time() + (86400 * 30), "/"); // 86400 = 1 day
setcookie('oar_billing_lastname', $order->getBillingAddress()->getLastName(), time() + (86400 * 30), "/"); // 86400 = 1 day
setcookie('oar_email', $order->getCustomerEmail(), time() + (86400 * 30), "/"); // 86400 = 1 day

else:
$params->redirectURL = $this->getBaseUrl() . 'checkout/onepage/success/';
if(isset($bitpay_redirect_url)):
$params->redirectURL = $bitpay_redirect_url;
else:
$params->redirectURL = $this->getBaseUrl() . 'checkout/onepage/success/';
endif;
endif;
} else {
if(isset($bitpay_redirect_url)):
$params->redirectURL = $bitpay_redirect_url;
else:
$params->redirectURL = $this->getBaseUrl() . 'sales/order/view/order_id/' . $order_id . '/';
endif;
}

$params->notificationURL = $this->getBaseUrl() . 'rest/V1/bitpay-bpcheckout/ipn';
$params->extendedNotifications = true;
$params->acceptanceWindow = 1200000;

$item = $this->BPC_Item( $config,$params);



//this creates the invoice with all of the config params from the item
$invoice = $this->BPC_createInvoice($item);
$invoiceData = json_decode($invoice);




//now we have to append the invoice transaction id for the callback verification
$invoiceID = $invoiceData->data->id;
Expand Down Expand Up @@ -342,7 +350,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
} //end execute function
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_4.09.2102';
return 'Bitpay_BPCheckout_Magento2_5.01.2102';

}

Expand Down
2 changes: 1 addition & 1 deletion 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":"4.09.2102",
"version":"5.01.2102",
"authors": [
{
"email": "[email protected]",
Expand Down
13 changes: 13 additions & 0 deletions code/Bitpay/BPCheckout/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@
<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_cancel_mapping" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Status mapping - BitPay invoice / Magento order on BitPay Canceled</label>
<comment><![CDATA[If set to TRUE, Magento will set the Order State to Canceled after the order has expired. If set to FALSE, no changes will be made to the Magento order]]></comment>
<source_model>Bitpay\BPCheckout\Model\Config\Source\Cancelstatus</source_model>
</field>

<field id="bitpay_redirect_url" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Custom Redirect URL</label>
<comment><![CDATA[If you have a custom url to redirect to (Thank You page, etc), enter the FULL URL here. You will need to customize any additional logic as needed]]></comment>
</field>



<field id="bitpay_ux" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Checkout Flow </label>
Expand Down
4 changes: 2 additions & 2 deletions 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.6.2102"></module>
</config>
<module name="Bitpay_BPCheckout" setup_version="5.1.2102"></module>
</config>

0 comments on commit a947653

Please sign in to comment.