diff --git a/tests/E2E/Checkout/TpayPaymentCheckoutTest.php b/tests/E2E/Checkout/TpayPaymentCheckoutTest.php index 8202ab1f..1e2cd745 100644 --- a/tests/E2E/Checkout/TpayPaymentCheckoutTest.php +++ b/tests/E2E/Checkout/TpayPaymentCheckoutTest.php @@ -7,14 +7,20 @@ use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\E2ETestCase; use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Account\LoginShopUserTrait; use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Order\CartTrait; +use Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Order\TpayTrait; final class TpayPaymentCheckoutTest extends E2ETestCase { use CartTrait; + use TpayTrait; use LoginShopUserTrait; - public function test_it_completes_the_checkout(): void + private const CARD_NUMBER = '4012 0010 3714 1112'; + + protected function setUp(): void { + parent::setUp(); + $this->loadFixtures([ 'addressed_cart.yaml', 'channel.yaml', @@ -30,9 +36,31 @@ public function test_it_completes_the_checkout(): void // the cart is already addressed, so we go straight to selecting a shipping method $this->showSelectingShippingMethodStep(); $this->processWithDefaultShippingMethod(); + } + + public function test_it_completes_the_checkout(): void + { $this->processWithPaymentMethod('tpay'); $this->placeOrder(); $this->assertPageTitleContains('Thank you!'); } + + public function test_it_completes_the_checkout_using_credit_card(): void + { + $this->processWithPaymentMethod('tpay_card'); + $this->fillCardData('John Doe', self::CARD_NUMBER, '123', '01', '2029'); + $this->placeOrder(); + + $this->assertPageTitleContains('Thank you!'); + } + + public function test_it_completes_the_checkout_using_blik(): void + { + $this->processWithPaymentMethod('tpay_blik'); + $this->fillBlikToken('777123'); + $this->placeOrder(); + + $this->assertPageTitleContains('Summary of your order'); + } } diff --git a/tests/E2E/Helper/Order/CartTrait.php b/tests/E2E/Helper/Order/CartTrait.php index 8285975d..0a733074 100644 --- a/tests/E2E/Helper/Order/CartTrait.php +++ b/tests/E2E/Helper/Order/CartTrait.php @@ -23,7 +23,13 @@ public function processWithDefaultShippingMethod(): void public function processWithPaymentMethod(string $paymentMethodCode): void { - $this->client->submitForm('Next', ['sylius_checkout_select_payment[payments][0][method]' => $paymentMethodCode]); + $this->client->executeScript( + sprintf( + 'document.querySelector(\'[name="sylius_checkout_select_payment[payments][0][method]"][value="%s"]\').checked = true', + $paymentMethodCode, + ), + ); + $this->client->submitForm('Next'); } public function placeOrder(): void diff --git a/tests/E2E/Helper/Order/TpayTrait.php b/tests/E2E/Helper/Order/TpayTrait.php new file mode 100644 index 00000000..9b8af404 --- /dev/null +++ b/tests/E2E/Helper/Order/TpayTrait.php @@ -0,0 +1,27 @@ +client->findElement(WebDriverBy::id('sylius_checkout_complete_tpay_card_holder_name'))->sendKeys($holderName); + $this->client->findElement(WebDriverBy::id('sylius_checkout_complete_tpay_card_number'))->sendKeys($cardNumber); + $this->client->findElement(WebDriverBy::id('sylius_checkout_complete_tpay_card_cvv'))->sendKeys($cvv); + $this->client->findElement(WebDriverBy::id('sylius_checkout_complete_tpay_card_expiration_date_year'))->sendKeys($year); + } + + public function fillBlikToken(string $blikToken): void + { + $this->client->findElement(WebDriverBy::id('sylius_checkout_complete_tpay_blik_token'))->sendKeys($blikToken); + } +} diff --git a/tests/E2E/Resources/fixtures/payment_method.yaml b/tests/E2E/Resources/fixtures/payment_method.yaml index 60cec54f..7b871be3 100644 --- a/tests/E2E/Resources/fixtures/payment_method.yaml +++ b/tests/E2E/Resources/fixtures/payment_method.yaml @@ -36,6 +36,7 @@ Sylius\Bundle\PayumBundle\Model\GatewayConfig: config: client_id: '' client_secret: '' + cards_api: '' type: 'card' production_mode: false gateway_tpay_blik: diff --git a/tests/mockoon_tpay.json b/tests/mockoon_tpay.json index 47d060cb..3ca45551 100644 --- a/tests/mockoon_tpay.json +++ b/tests/mockoon_tpay.json @@ -20,19 +20,81 @@ "body": "{\n \"result\": \"success\",\n \"requestId\": \"d3a9826d92c48cb8c185\",\n \"transactionId\": \"ta_bKvkJX9Knk9Ol4od\",\n \"title\": \"TR-CWM-CS7LW1X\",\n \"posId\": \"ps_e4dkPVDEm4Jg726q\",\n \"status\": \"pending\",\n \"date\": {\n \"creation\": \"2024-06-12 21:29:35\",\n \"realization\": null\n },\n \"amount\": 0.1,\n \"currency\": \"PLN\",\n \"description\": \"Test transaction\",\n \"hiddenDescription\": \"\",\n \"payer\": {\n \"payerId\": \"py_a9rjlZWxRLdG1bqY\",\n \"email\": \"jan.nowak@example.com\",\n \"name\": \"Jan Nowak\",\n \"phone\": \"\",\n \"address\": \"\",\n \"city\": \"\",\n \"country\": \"PL\",\n \"postalCode\": \"\"\n },\n \"payments\": {\n \"status\": \"pending\",\n \"method\": null,\n \"amountPaid\": 0,\n \"date\": {\n \"realization\": null\n }\n },\n \"transactionPaymentUrl\": \"{{body 'callbacks.payerUrls.success'}}\"\n}", "latency": 0, "statusCode": 200, - "label": "", + "label": "Redirect", "headers": [], "bodyType": "INLINE", "filePath": "", "databucketID": "", "sendFileAsBody": false, - "rules": [], + "rules": [ + { + "target": "body", + "modifier": "pay.groupId", + "value": "", + "invert": false, + "operator": "null" + } + ], "rulesOperator": "OR", "disableTemplating": false, "fallbackTo404": false, "default": true, "crudKey": "id", "callbacks": [] + }, + { + "uuid": "ed30e0d4-13ca-4b92-acb9-65946ef1520d", + "body": "{\n \"result\": \"success\",\n \"requestId\": \"d3a9826d92c48cb8c185\",\n \"transactionId\": \"ta_bKvkJX9Knk9Ol4od\",\n \"title\": \"TR-CWM-CS7LW1X\",\n \"posId\": \"ps_e4dkPVDEm4Jg726q\",\n \"status\": \"pending\",\n \"date\": {\n \"creation\": \"2024-06-12 21:29:35\",\n \"realization\": null\n },\n \"amount\": 0.1,\n \"currency\": \"PLN\",\n \"description\": \"Test transaction\",\n \"hiddenDescription\": \"\",\n \"payer\": {\n \"payerId\": \"py_a9rjlZWxRLdG1bqY\",\n \"email\": \"jan.nowak@example.com\",\n \"name\": \"Jan Nowak\",\n \"phone\": \"\",\n \"address\": \"\",\n \"city\": \"\",\n \"country\": \"PL\",\n \"postalCode\": \"\"\n },\n \"payments\": {\n \"status\": \"pending\",\n \"method\": null,\n \"amountPaid\": 0,\n \"date\": {\n \"realization\": null\n }\n },\n \"transactionPaymentUrl\": \"{{body 'callbacks.payerUrls.success'}}\"\n}\n{{setGlobalVar 'callbacks_payers_urls_success' (body 'callbacks.payerUrls.success')}}", + "latency": 0, + "statusCode": 200, + "label": "Card", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [ + { + "target": "body", + "modifier": "pay.groupId", + "value": "103", + "invert": false, + "operator": "equals" + } + ], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": false, + "crudKey": "id", + "callbacks": [] + }, + { + "uuid": "3f11934d-183b-4e7d-b127-38f7bdaddb55", + "body": "{\n \"result\": \"success\",\n \"requestId\": \"b6325d51e8c4b9130476\",\n \"transactionId\": \"ta_jrkNGj5L29pnlbqw\",\n \"title\": \"TR-BRA-CCP1S9X\",\n \"posId\": \"ps_NyRBLzV5kelrpjaM\",\n \"status\": \"pending\",\n \"date\": {\n \"creation\": \"2024-05-08 21:01:15\",\n \"realization\": null\n },\n \"amount\": 0.1,\n \"currency\": \"PLN\",\n \"description\": \"test transaction via BLIK\",\n \"hiddenDescription\": \"\",\n \"payer\": {\n \"payerId\": \"py_a9rjlZ3qyPPG1bqY\",\n \"email\": \"\",\n \"name\": \"Jan Nowak\",\n \"phone\": \"\",\n \"address\": \"\",\n \"city\": \"\",\n \"country\": \"PL\",\n \"postalCode\": \"\"\n },\n \"payments\": {\n \"status\": \"pending\",\n \"method\": \"pay_by_link\",\n \"amountPaid\": 0,\n \"date\": {\n \"realization\": null\n }\n },\n \"transactionPaymentUrl\": \"\"\n}", + "latency": 0, + "statusCode": 200, + "label": "Blik", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [ + { + "target": "body", + "modifier": "pay.groupId", + "value": "150", + "invert": false, + "operator": "equals" + } + ], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": false, + "crudKey": "id", + "callbacks": [] } ], "responseMode": null @@ -65,6 +127,35 @@ } ], "responseMode": null + }, + { + "uuid": "0b6be9e5-c227-4fa9-a8c5-fc7a0daf9881", + "type": "http", + "documentation": "", + "method": "post", + "endpoint": "transactions/:id/pay", + "responses": [ + { + "uuid": "53879045-689d-4e82-a5a3-583af9b15177", + "body": "{\n \"result\": \"success\",\n \"requestId\": \"858fa92dc62db44e2c1f\",\n \"transactionId\": \"ta_9jQLGqzeY2eOVK01\",\n \"title\": \"TR-CWM-CNYHA6X\",\n \"posId\": \"ps_e4dkPVDEm4Jg726q\",\n \"status\": \"pending\",\n \"date\": {\n \"creation\": \"2024-06-06 21:31:35\",\n \"realization\": null\n },\n \"amount\": 0.1,\n \"currency\": \"PLN\",\n \"description\": \"Testowa płatność kartowa\",\n \"hiddenDescription\": \"\",\n \"payer\": {\n \"payerId\": \"py_a9rjlZWxRLdG1bqY\",\n \"email\": \"jan.nowak@example.com\",\n \"name\": \"Jan Nowak\",\n \"phone\": \"\",\n \"address\": \"\",\n \"city\": \"\",\n \"country\": \"PL\",\n \"postalCode\": \"\"\n },\n \"payments\": {\n \"status\": \"pending\",\n \"method\": \"pay_by_link\",\n \"amountPaid\": 0,\n \"date\": {\n \"realization\": null\n }\n },\n \"transactionPaymentUrl\": \"{{getGlobalVar 'callbacks_payers_urls_success'}}\"\n}", + "latency": 0, + "statusCode": 200, + "label": "", + "headers": [], + "bodyType": "INLINE", + "filePath": "", + "databucketID": "", + "sendFileAsBody": false, + "rules": [], + "rulesOperator": "OR", + "disableTemplating": false, + "fallbackTo404": false, + "default": true, + "crudKey": "id", + "callbacks": [] + } + ], + "responseMode": null } ], "rootChildren": [ @@ -75,6 +166,10 @@ { "type": "route", "uuid": "5b0daede-d7b8-4329-8ee4-cfedffc699d0" + }, + { + "type": "route", + "uuid": "0b6be9e5-c227-4fa9-a8c5-fc7a0daf9881" } ], "proxyMode": false,