Skip to content

Commit

Permalink
Merge pull request #17 from thejoshualewis/master
Browse files Browse the repository at this point in the history
Order Status Updates
  • Loading branch information
thejoshualewis committed Jun 18, 2019
2 parents 8a19cbc + 8b9c53e commit 3e9abc7
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class Pendingpayment extends Status
/**
* @var string[]
*/
protected $_stateStatuses = [Order::STATE_PENDING_PAYMENT];
protected $_stateStatuses = [Order::STATE_NEW];
}
6 changes: 3 additions & 3 deletions code/Bitpay/BPCheckout/Model/IpnManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function postIpn()

$order->addStatusHistoryComment('BitPay Invoice <a href = "http://' . $item->endpoint . '/dashboard/payments/' . $order_invoice . '" target = "_blank">' . $order_invoice . '</a> processing has been completed.');
if($bitpay_ipn_mapping != 'processing'):
$order->setState(Order::STATE_PENDING_PAYMENT)->setStatus(Order::STATE_PENDING_PAYMENT);
$order->setState(Order::STATE_NEW)->setStatus(Order::STATE_NEW);
else:
$order->setState(Order::STATE_PROCESSING)->setStatus(Order::STATE_PROCESSING);
endif;
Expand All @@ -122,7 +122,7 @@ public function postIpn()
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_PENDING_PAYMENT)->setStatus(Order::STATE_PENDING_PAYMENT);
$order->setState(Order::STATE_NEW)->setStatus(Order::STATE_NEW);
$order->save();
return true;

Expand Down Expand Up @@ -157,6 +157,6 @@ public function postIpn()
}
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_3.0.4.0';
return 'Bitpay_BPCheckout_Magento2_3.0.5.0';
}
}
28 changes: 21 additions & 7 deletions code/Bitpay/BPCheckout/Observer/BPRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class BPRedirect implements ObserverInterface
protected $coreRegistry;
protected $_redirect;
protected $_response;
public $orderRepository;

public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\App\ResponseFactory $responseFactory,
Expand All @@ -21,7 +22,8 @@ public function __construct(
\Magento\Framework\Registry $registry,
\Magento\Framework\App\ActionFlag $actionFlag,
\Magento\Framework\App\Response\RedirectInterface $redirect,
\Magento\Framework\App\ResponseInterface $response
\Magento\Framework\App\ResponseInterface $response,
\Magento\Sales\Model\OrderRepository $orderRepository
) {
$this->coreRegistry = $registry;
$this->_moduleList = $moduleList;
Expand All @@ -33,6 +35,7 @@ public function __construct(
$this->_actionFlag = $actionFlag;
$this->_redirect = $redirect;
$this->_response = $response;
$this->orderRepository = $orderRepository;

}

Expand Down Expand Up @@ -79,8 +82,16 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$order_id = $order_ids[0];
$order = $this->getOrder($order_id);
$order_id_long = $order->getIncrementId();
if ($order->getPayment()->getMethodInstance()->getCode() == 'bpcheckout') {




if ($order->getPayment()->getMethodInstance()->getCode() == 'bpcheckout') {
#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');
$bitpay_token = $this->getStoreConfig('payment/bpcheckout/bitpay_devtoken');
Expand All @@ -103,16 +114,19 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$params->currency = $order['base_currency_code']; //set as needed

#buyer email
$bitpay_capture_email = $this->getStoreConfig('payment/bpcheckout/bitpay_capture_email');
$customerSession = $objectManager->create('Magento\Customer\Model\Session');

$buyerInfo = (new \stdClass());
if ($customerSession->isLoggedIn()) {
if ($bitpay_capture_email == 1):
$buyerInfo = (new \stdClass());

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

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

Expand Down Expand Up @@ -181,7 +195,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
} //end execute function
public function getExtensionVersion()
{
return 'Bitpay_BPCheckout_Magento2_3.0.4.0';
return 'Bitpay_BPCheckout_Magento2_3.0.5.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.4",
"version":"3.0.5",
"authors": [
{
"email": "integrations@bitpay.com",
Expand Down
8 changes: 1 addition & 7 deletions code/Bitpay/BPCheckout/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@
<comment><![CDATA[If this is set to <b>Redirect</b>, then the customer will be redirected to <b>BitPay</b> to checkout, and return to the checkout page once the payment is made.<br><br>If this is set to <b>Modal</b>, the user will stay on your e-commerce site and complete the transaction.]]></comment>
<source_model>Bitpay\BPCheckout\Model\Config\Source\Ux</source_model>
</field>

<field id="bitpay_capture_email" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Auto-Capture Email</label>
<comment><![CDATA[Should BitPay try to auto-add the client's email address?<br>If <b>Yes</b>, the client will not be able to change the email address on the BitPay invoice.<br>If <b>No</b>, they will be able to add their own email address when paying the invoice.]]></comment>
<source_model>Bitpay\BPCheckout\Model\Config\Source\Capture</source_model>
</field>



<field id="specificcountry" translate="label" type="multiselect" sortOrder="41" showInDefault="1"
showInWebsite="1" showInStore="0">
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.4.0"></module>
<module name="Bitpay_BPCheckout" setup_version="3.0.5.0"></module>
</config>

0 comments on commit 3e9abc7

Please sign in to comment.