Skip to content

Commit

Permalink
Merge pull request #108 from p-maguire/10.0.x
Browse files Browse the repository at this point in the history
SP-1032: Add platformInfo
  • Loading branch information
bobbrodie authored Nov 26, 2024
2 parents ceb9a00 + a7dce73 commit 1c35d8e
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 203 deletions.
10 changes: 0 additions & 10 deletions Block/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ public function getBitpayEnv(): ?string
return $this->config->getBitpayEnv();
}

/**
* Get modal param
*
* @return int
*/
public function getModalParam(): int
{
return (int) $this->getRequest()->getParam('m');
}

/**
* Get order id
*
Expand Down
48 changes: 10 additions & 38 deletions Model/BPRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,14 @@ public function execute(ResultInterface $defaultResult, string $returnId = null)
try {
$baseUrl = $this->config->getBaseUrl();
$order = $this->setToPendingAndOverrideMagentoStatus($order);
$modal = $this->config->getBitpayUx() === 'modal';
$redirectUrl = $this->url->getUrl('bitpay-invoice', ['_query' => ['order_id' => $incrementId]]);
if ($isStandardCheckoutSuccess) {
$this->checkoutSession->setLastSuccessQuoteId($order->getQuoteId());
if (!$modal) {
$redirectUrl = $this->url->getUrl('checkout/onepage/success', [
'_query' => ['return_id' => $returnHash]
]);
}
$redirectUrl = $this->url->getUrl('checkout/onepage/success', [
'_query' => ['return_id' => $returnHash]
]);
}
$params = $this->getParams($order, $incrementId, $modal, $redirectUrl, $baseUrl);
$params = $this->getParams($order, $incrementId, $redirectUrl, $baseUrl);
$billingAddressData = $order->getBillingAddress()->getData();
$this->setSessionCustomerData($billingAddressData, $order->getCustomerEmail(), $incrementId);
$client = $this->client->initialize();
Expand All @@ -153,34 +150,11 @@ public function execute(ResultInterface $defaultResult, string $returnId = null)
$invoice->getAcceptanceWindow()
);
$this->transactionRepository->add($incrementId, $invoiceID, 'new');

switch ($modal) {
case true:
case 1:
#set some info for guest checkout
$this->setSessionCustomerData($billingAddressData, $order->getCustomerEmail(), $incrementId);

$redirectParams = [
'invoiceID' => $invoiceID,
'order_id' => $incrementId,
'm' => 1,
];
if ($isStandardCheckoutSuccess) {
$redirectParams['return_id'] = $returnHash;
}
$redirectUrl = $this->url->getUrl('bitpay-invoice', ['_query' => $redirectParams]);

return $this->resultFactory->create(
\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT
)
->setUrl($redirectUrl);
case false:
default:
return $this->resultFactory->create(
\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT
)
->setUrl($invoice->getUrl());
}

return $this->resultFactory->create(
\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT
)
->setUrl($invoice->getUrl());
} catch (\Exception $exception) {
return $this->deleteOrderAndRedirectToCart($exception, $order);
} catch (\Error $error) {
Expand Down Expand Up @@ -229,15 +203,13 @@ private function setToPendingAndOverrideMagentoStatus(OrderInterface $order): Or
*
* @param OrderInterface $order
* @param string|null $incrementId
* @param bool $modal
* @param string $redirectUrl
* @param string $baseUrl
* @return DataObject
*/
private function getParams(
OrderInterface $order,
?string $incrementId,
bool $modal,
string $redirectUrl,
string $baseUrl
): DataObject {
Expand All @@ -251,7 +223,7 @@ private function getParams(
'currency' => $order['base_currency_code'],
'buyer' => $buyerInfo->getData(),
'orderId' => trim($incrementId),
'redirectURL' => !$modal ? $redirectUrl . "&m=0" : $redirectUrl,
'redirectURL' => $redirectUrl,
'notificationURL' => $baseUrl . 'rest/V1/bitpay-bpcheckout/ipn',
'closeURL' => $baseUrl . 'rest/V1/bitpay-bpcheckout/close?orderID=' . $incrementId,
'extendedNotifications' => true
Expand Down
3 changes: 2 additions & 1 deletion Model/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function initialize(): \BitPaySDK\Client
$serializedTokenData = $this->serializer->unserialize($tokenData);
$merchantToken = $serializedTokenData['data'][0]['token'];
$tokens = new Tokens($merchantToken);
$platformInfo = 'BitPay_Magento2_v10.0.0';

return \BitPaySDK\Client::createWithData($env, $privateKeyPath, $tokens, $password);
return \BitPaySDK\Client::createWithData($env, $privateKeyPath, $tokens, $password, null, $platformInfo);
}
}
10 changes: 0 additions & 10 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,6 @@ public function getBPCheckoutOrderStatus():? string
return $this->scopeConfig->getValue(self::BPCHECKOUT_ORDER_STATUS, ScopeInterface::SCOPE_STORE);
}

/**
* Get BitPay Ux
*
* @return string|null
*/
public function getBitpayUx():? string
{
return $this->scopeConfig->getValue(self::BITPAY_UX, ScopeInterface::SCOPE_STORE);
}

/**
* Get BitPay CheckoutSuccess
*
Expand Down
29 changes: 0 additions & 29 deletions Model/Config/Source/Ux.php

This file was deleted.

8 changes: 0 additions & 8 deletions Test/Integration/Block/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ public function testGetBitpayEnv(): void
$this->assertEquals('test', $this->index->getBitpayEnv());
}

public function testGetModalParam(): void
{
$requst = $this->context->getRequest();
$requst->setParams(['m' => '1']);

$this->assertEquals(1, $this->index->getModalParam());
}

public function testOrderId(): void
{
$requst = $this->context->getRequest();
Expand Down
8 changes: 0 additions & 8 deletions Test/Integration/Model/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ public function testGetBaseUrl(): void
$this->assertEquals($url, $this->config->getBaseUrl());
}

/**
* @magentoConfigFixture current_store payment/bpcheckout/bitpay_ux modal
*/
public function testGetBitpayUx(): void
{
$this->assertEquals('modal', $this->config->getBitpayUx());
}

/**
* @magentoConfigFixture current_store payment/bpcheckout/bitpay_ipn_mapping pending
*/
Expand Down
10 changes: 0 additions & 10 deletions Test/Unit/Block/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ public function testGetBitpayEnv(): void
$this->assertEquals(self::ENV, $this->index->getBitpayEnv());
}

public function testGetModalParam(): void
{
$this->request->expects($this->once())
->method('getParam')
->with('m')
->willReturn(1);

$this->assertEquals(1, $this->index->getModalParam());
}

public function testGetOrderId(): void
{
$this->request->expects($this->once())->method('getParam')
Expand Down
25 changes: 4 additions & 21 deletions Test/Unit/Model/BPRedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,10 @@ public function setUp(): void
}

/**
* @param $ux
* @return void
* @throws \Exception
* @dataProvider getUxDataProvider
*/
public function testExecute($ux): void
public function testExecute(): void
{
$incrementId = '0000012121';
$bitpayToken = 'A32nRffe34dF2312vmm';
Expand Down Expand Up @@ -192,29 +190,15 @@ public function testExecute($ux): void
$this->bitpayInvoiceRepository->expects($this->once())->method('add');
$this->transactionRepository->expects($this->once())->method('add');

if ($ux === 'modal') {
$this->prepareResponse();
} else {
$result = $this->getMock(Redirect::class);
$result->expects($this->once())->method('setUrl')->willReturnSelf();
$this->resultFactory->expects($this->once())->method('create')->willReturn($result);
}
$result = $this->getMock(Redirect::class);
$result->expects($this->once())->method('setUrl')->willReturnSelf();
$this->resultFactory->expects($this->once())->method('create')->willReturn($result);

$page = $this->getMock(\Magento\Framework\View\Result\Page::class);

$this->bpRedirect->execute($page);
}

/**
* @return array[]
*/
public function getUxDataProvider(): array
{
return [
['modal'], ['redirect']
];
}

public function testExecuteNoOrderId(): void
{
$response = $this->getMock(\Magento\Framework\HTTP\PhpEnvironment\Response::class);
Expand Down Expand Up @@ -341,7 +325,6 @@ private function getOrder(string $incrementId, MockObject $payment, MockObject $
private function prepareConfig(string $baseUrl, string $ux): void
{
$this->config->expects($this->once())->method('getBPCheckoutOrderStatus')->willReturn('pending');
$this->config->expects($this->once())->method('getBitpayUx')->willReturn($ux);
$this->config->expects($this->once())->method('getBaseUrl')->willReturn($baseUrl);
}

Expand Down
9 changes: 0 additions & 9 deletions Test/Unit/Model/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ public function setUp(): void
);
}

public function testGetBitpayUx(): void
{
$this->scopeConfig->expects($this->once())
->method('getValue')
->with(Config::BITPAY_UX, ScopeInterface::SCOPE_STORE)
->willReturn('modal');
$this->assertEquals('modal', $this->config->getBitpayUx());
}

public function testGetBitpayIpnMapping(): void
{
$this->scopeConfig->expects($this->once())
Expand Down
7 changes: 0 additions & 7 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@
<source_model>Bitpay\BPCheckout\Model\Config\Source\Cancelstatus</source_model>
</field>


<field id="bitpay_ux" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Checkout Flow </label>
<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_checkout_success" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Checkout Success</label>
<comment><![CDATA[Note: Using the standard checkout success page may require updates to your theme.]]></comment>
Expand Down
68 changes: 16 additions & 52 deletions view/frontend/templates/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,24 @@
$configValue = $block->getBaseSecureUrl();
$env = $block->getBitpayEnv();
$order_id = $block->getOrderId();
if ($block->getModalParam() === 1): ?>
?>
<h2 id="bitpay-header">Thank you for your purchase.</h2>
<div id="success-bitpay-page">
<?php /** @var $block \Magento\Checkout\Block\Onepage\Success */ ?>
<div class="checkout-success">
<?php if ($order_id): ?>
<p><?= /* @noEscape */ __('Your order # is: <b>' . $order_id . '</b> ') ?></p>
<p>
<?= /* @noEscape */ __('We\'ll email you an order confirmation with details and tracking info. ') ?>
</p>
<?php endif; ?>

<script type="text/x-magento-init">
{
"*": {
"Bitpay_BPCheckout/js/bitpay/checkout/index": {
"env": "<?= /* @noEscape */ $env ?>",
"baseUrl": "<?= /* @noEscape */ $configValue ?>"
}
}
}

</script>
<!--page to show with modal-->
<h2 id="bitpay-header"><?= /* @noEscape */ __('Loading BitPay Invoice...') ?></h2>
<div id="success-bitpay-page" style="display:none;">
<?php /** @var $block \Magento\Checkout\Block\Onepage\Success */ ?>
<div class="checkout-success">
<?php if ($order_id): ?>
<p><?= /* @noEscape */ __('Your order # is: <b>' . $order_id . '</b> ') ?></p>
<p>
<?= /* @noEscape */ __('We\'ll email you an order confirmation with details and tracking info. ') ?>
</p>
<?php endif; ?>
<div class="actions-toolbar">
<div class="primary">
<a class="action primary continue"
href="/"><span><?= $block->escapeHtml(__('Continue Shopping')) ?></span></a>
</div>
</div>
</div>
</div>
<!--end page to show with modal-->

<!--page to show with redirect-->
<?php else: ?>
<h2 id="bitpay-header">Thank you for your purchase.</h2>
<div id="success-bitpay-page">
<?php /** @var $block \Magento\Checkout\Block\Onepage\Success */ ?>
<div class="checkout-success">
<?php if ($order_id): ?>
<p><?= /* @noEscape */ __('Your order # is: <b>' . $order_id . '</b> ') ?></p>
<p>
<?= /* @noEscape */ __('We\'ll email you an order confirmation with details and tracking info. ') ?>
</p>
<?php endif; ?>

<div class="actions-toolbar">
<div class="primary">
<a class="action primary continue"
href="/"><span><?= $block->escapeHtml(__('Continue Shopping')) ?></span></a>
</div>
<div class="actions-toolbar">
<div class="primary">
<a class="action primary continue"
href="/"><span><?= $block->escapeHtml(__('Continue Shopping')) ?></span></a>
</div>
</div>
</div>
<?php endif; ?>
</div>
<!--end page to show with redirect-->

0 comments on commit 1c35d8e

Please sign in to comment.