From 0c93740e2eeb2f8232ea1dc434d91438dc54a9eb Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 22 Nov 2024 12:38:45 -0500 Subject: [PATCH 1/5] SP-1032: Add platform info --- Model/Client.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Model/Client.php b/Model/Client.php index 4fb542d..f990252 100755 --- a/Model/Client.php +++ b/Model/Client.php @@ -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, $platformInfo); } } From 50232a6ffd0113bc2ecb7935a0e3e2d4910833ae Mon Sep 17 00:00:00 2001 From: Patrick Date: Fri, 22 Nov 2024 13:23:55 -0500 Subject: [PATCH 2/5] SP-1032: Update Client --- Model/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Client.php b/Model/Client.php index f990252..170bb08 100755 --- a/Model/Client.php +++ b/Model/Client.php @@ -41,6 +41,6 @@ public function initialize(): \BitPaySDK\Client $tokens = new Tokens($merchantToken); $platformInfo = 'BitPay_Magento2_v10.0.0'; - return \BitPaySDK\Client::createWithData($env, $privateKeyPath, $tokens, $password, $platformInfo); + return \BitPaySDK\Client::createWithData($env, $privateKeyPath, $tokens, $password, null, $platformInfo); } } From debbb47bf8039964bd016c1711ab46e2475b9f3f Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 25 Nov 2024 16:01:05 -0500 Subject: [PATCH 3/5] SP-1104: Remove modal option from checkout --- Block/Index.php | 10 ---- Model/BPRedirect.php | 48 ++++--------------- Model/Config.php | 10 ---- Model/Config/Source/Ux.php | 29 ------------ Test/Integration/Model/ConfigTest.php | 8 ---- Test/Unit/Model/BPRedirectTest.php | 22 ++------- Test/Unit/Model/ConfigTest.php | 9 ---- view/frontend/templates/index.phtml | 68 +++++++-------------------- 8 files changed, 29 insertions(+), 175 deletions(-) delete mode 100755 Model/Config/Source/Ux.php diff --git a/Block/Index.php b/Block/Index.php index 5445fb7..c4e641b 100644 --- a/Block/Index.php +++ b/Block/Index.php @@ -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 * diff --git a/Model/BPRedirect.php b/Model/BPRedirect.php index 0eeb638..2c4b810 100755 --- a/Model/BPRedirect.php +++ b/Model/BPRedirect.php @@ -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(); @@ -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) { @@ -229,7 +203,6 @@ private function setToPendingAndOverrideMagentoStatus(OrderInterface $order): Or * * @param OrderInterface $order * @param string|null $incrementId - * @param bool $modal * @param string $redirectUrl * @param string $baseUrl * @return DataObject @@ -237,7 +210,6 @@ private function setToPendingAndOverrideMagentoStatus(OrderInterface $order): Or private function getParams( OrderInterface $order, ?string $incrementId, - bool $modal, string $redirectUrl, string $baseUrl ): DataObject { @@ -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 diff --git a/Model/Config.php b/Model/Config.php index 09215e9..1253e26 100755 --- a/Model/Config.php +++ b/Model/Config.php @@ -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 * diff --git a/Model/Config/Source/Ux.php b/Model/Config/Source/Ux.php deleted file mode 100755 index 77c630a..0000000 --- a/Model/Config/Source/Ux.php +++ /dev/null @@ -1,29 +0,0 @@ - 'Redirect', - 'modal' => 'Modal', - ]; - } -} diff --git a/Test/Integration/Model/ConfigTest.php b/Test/Integration/Model/ConfigTest.php index 2afa36e..84e23e1 100755 --- a/Test/Integration/Model/ConfigTest.php +++ b/Test/Integration/Model/ConfigTest.php @@ -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 */ diff --git a/Test/Unit/Model/BPRedirectTest.php b/Test/Unit/Model/BPRedirectTest.php index 9060660..d01819b 100755 --- a/Test/Unit/Model/BPRedirectTest.php +++ b/Test/Unit/Model/BPRedirectTest.php @@ -145,7 +145,6 @@ public function setUp(): void * @param $ux * @return void * @throws \Exception - * @dataProvider getUxDataProvider */ public function testExecute($ux): void { @@ -192,29 +191,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); @@ -341,7 +326,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); } diff --git a/Test/Unit/Model/ConfigTest.php b/Test/Unit/Model/ConfigTest.php index ed9b00e..2df14d0 100755 --- a/Test/Unit/Model/ConfigTest.php +++ b/Test/Unit/Model/ConfigTest.php @@ -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()) diff --git a/view/frontend/templates/index.phtml b/view/frontend/templates/index.phtml index a2e5107..94d4487 100644 --- a/view/frontend/templates/index.phtml +++ b/view/frontend/templates/index.phtml @@ -3,60 +3,24 @@ $configValue = $block->getBaseSecureUrl(); $env = $block->getBitpayEnv(); $order_id = $block->getOrderId(); -if ($block->getModalParam() === 1): ?> +?> +

Thank you for your purchase.

+
+ +
+ +

' . $order_id . ' ') ?>

+

+ +

+ - - -

- - - - - -

Thank you for your purchase.

-
- -
- -

' . $order_id . ' ') ?>

-

- -

- - - - +
From 5de42bb6d58fdee8aed4dab9d2ea965cb4092058 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 25 Nov 2024 16:11:18 -0500 Subject: [PATCH 4/5] SP-1104: Remove admin option --- etc/adminhtml/system.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 332e396..ca61dbd 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -121,13 +121,6 @@ Bitpay\BPCheckout\Model\Config\Source\Cancelstatus - - - - Redirect, then the customer will be redirected to BitPay to checkout, and return to the checkout page once the payment is made.

If this is set to Modal, the user will stay on your e-commerce site and complete the transaction.]]>
- Bitpay\BPCheckout\Model\Config\Source\Ux -
- From a7dce731ee9c550ef87a8b08de42f991672306da Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 25 Nov 2024 16:28:43 -0500 Subject: [PATCH 5/5] SP-1104: Fix tests --- Test/Integration/Block/IndexTest.php | 8 -------- Test/Unit/Block/IndexTest.php | 10 ---------- Test/Unit/Model/BPRedirectTest.php | 3 +-- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/Test/Integration/Block/IndexTest.php b/Test/Integration/Block/IndexTest.php index 28a4206..32befff 100755 --- a/Test/Integration/Block/IndexTest.php +++ b/Test/Integration/Block/IndexTest.php @@ -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(); diff --git a/Test/Unit/Block/IndexTest.php b/Test/Unit/Block/IndexTest.php index fe1f3a1..5b49c81 100755 --- a/Test/Unit/Block/IndexTest.php +++ b/Test/Unit/Block/IndexTest.php @@ -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') diff --git a/Test/Unit/Model/BPRedirectTest.php b/Test/Unit/Model/BPRedirectTest.php index d01819b..39d8c94 100755 --- a/Test/Unit/Model/BPRedirectTest.php +++ b/Test/Unit/Model/BPRedirectTest.php @@ -142,11 +142,10 @@ public function setUp(): void } /** - * @param $ux * @return void * @throws \Exception */ - public function testExecute($ux): void + public function testExecute(): void { $incrementId = '0000012121'; $bitpayToken = 'A32nRffe34dF2312vmm';