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

guest order updates #18

Merged
merged 2 commits into from
Jun 19, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/Bitpay/BPCheckout/Model/IpnManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ public function postIpn()
}
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_3.0.5.0';
return 'Bitpay_BPCheckout_Magento2_3.0.6.0';
}
}
74 changes: 37 additions & 37 deletions code/Bitpay/BPCheckout/Observer/BPRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,25 @@ public function execute(\Magento\Framework\Event\Observer $observer)
{
$controller = $observer->getControllerAction();
$this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
$level = 1;

include(dirname(__DIR__, $level)."/BitPayLib/BPC_Client.php");
include(dirname(__DIR__, $level)."/BitPayLib/BPC_Configuration.php");
include(dirname(__DIR__, $level)."/BitPayLib/BPC_Invoice.php");
include(dirname(__DIR__, $level)."/BitPayLib/BPC_Item.php");


include dirname(__DIR__, $level) . "/BitPayLib/BPC_Client.php";
include dirname(__DIR__, $level) . "/BitPayLib/BPC_Configuration.php";
include dirname(__DIR__, $level) . "/BitPayLib/BPC_Invoice.php";
include dirname(__DIR__, $level) . "/BitPayLib/BPC_Item.php";

$order_ids = $observer->getEvent()->getOrderIds();
$order_id = $order_ids[0];
$order = $this->getOrder($order_id);
$order_id_long = $order->getIncrementId();




if ($order->getPayment()->getMethodInstance()->getCode() == 'bpcheckout') {
#set to pending and override magento coding
$order->setState('new',true);
$order->setStatus('pending',true);
#set to pending and override magento coding
$order->setState('new', true);
$order->setStatus('pending', true);

$order->save();
#get the environment
$env = $this->getStoreConfig('payment/bpcheckout/bitpay_endpoint');
Expand All @@ -115,40 +111,45 @@ public function execute(\Magento\Framework\Event\Observer $observer)

#buyer email
$customerSession = $objectManager->create('Magento\Customer\Model\Session');

$buyerInfo = (new \stdClass());
$guest_login = true;
if ($customerSession->isLoggedIn()) {
$buyerInfo->name = $customerSession->getCustomer()->getName();
$buyerInfo->email = $customerSession->getCustomer()->getEmail();
$params->buyer = $buyerInfo;
}else{
$buyerInfo->name = $order->getBillingAddress()->getFirstName(). ' '.$order->getBillingAddress()->getLastName();
$guest_login = false;
$buyerInfo->name = $customerSession->getCustomer()->getName();
$buyerInfo->email = $customerSession->getCustomer()->getEmail();

} else {
$buyerInfo->name = $order->getBillingAddress()->getFirstName() . ' ' . $order->getBillingAddress()->getLastName();
$buyerInfo->email = $order->getCustomerEmail();
}
;
$params->buyer = $buyerInfo;

$params->orderId = trim($order_id_long);

#ipn

if (!$customerSession->isLoggedIn()) {
#leave alone
$params->redirectURL = $this->getBaseUrl() . 'checkout/onepage/success/';
if ($modal == false):
$params->redirectURL .= '?bp=1';
if ($guest_login) { #user is a guest
#leave alone
if ($modal == false):
#this will send them back to the order/returns page to lookup
$params->redirectURL = $this->getBaseUrl() . 'sales/guest/form';
#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/';
endif;
}
if ($customerSession->isLoggedIn()) {
} else {
$params->redirectURL = $this->getBaseUrl() . 'sales/order/view/order_id/' . $order_id . '/';
if ($modal == false):
endif;
}

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


#cartfix for modal
$params->cartFix = $this->getBaseUrl() . 'cartfix/cartfix?order_id=' . $order_id;
$item = (new \Bitpay\BPCheckout\BitPayLib\BPC_Item($config, $params));
Expand All @@ -169,7 +170,6 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$table_name = $resource->getTableName('bitpay_transactions');

$sql = "INSERT INTO $table_name (order_id,transaction_id,transaction_status) VALUES ('" . $order_id_long . "','" . $invoiceID . "','new')";


$connection->query($sql);
switch ($modal) {
Expand All @@ -187,15 +187,15 @@ public function execute(\Magento\Framework\Event\Observer $observer)
break;
case false:
default:
$this->_redirect->redirect($this->_response, $invoice->BPC_getInvoiceURL());;
break;

$this->_redirect->redirect($this->_response, $invoice->BPC_getInvoiceURL());
break;
}
}
} //end execute function
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_3.0.5.0';
return 'Bitpay_BPCheckout_Magento2_3.0.6.0';

}

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":"3.0.5",
"version":"3.0.6",
"authors": [
{
"email": "integrations@bitpay.com",
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.0.5.0"></module>
<module name="Bitpay_BPCheckout" setup_version="3.0.6.0"></module>
</config>
15 changes: 15 additions & 0 deletions code/Bitpay/BPCheckout/view/frontend/web/js/bitpay/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,18 @@ if (window.location.href.indexOf("checkout/onepage/success/") > -1 && getCookie(
}, 750);

}
//guest checkout
//autofill the guest info
if(window.location.pathname.indexOf('sales/guest/form') != -1){
//autofill form
setTimeout(function(){
jQuery("#oar-order-id").val(getCookie("oar_order_id"))
jQuery("#oar-billing-lastname").val(getCookie("oar_billing_lastname"))
jQuery("#oar_email").val(getCookie("oar_email"))
deleteCookie("oar_order_id")
deleteCookie("oar_billing_lastname")
deleteCookie("oar_email")

},
1500);
}