Skip to content

Commit

Permalink
Cover happy path for Tpay payments with E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed Sep 16, 2024
1 parent 404f832 commit 348cf53
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 4 deletions.
30 changes: 29 additions & 1 deletion tests/E2E/Checkout/TpayPaymentCheckoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');
}
}
8 changes: 7 additions & 1 deletion tests/E2E/Helper/Order/CartTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions tests/E2E/Helper/Order/TpayTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusTpayPlugin\E2E\Helper\Order;

use Facebook\WebDriver\WebDriverBy;
use Symfony\Component\Panther\Client;

/**
* @property Client $client
*/
trait TpayTrait
{
public function fillCardData(string $holderName, string $cardNumber, string $cvv, string $month, string $year): void
{
$this->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);
}
}
1 change: 1 addition & 0 deletions tests/E2E/Resources/fixtures/payment_method.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Sylius\Bundle\PayumBundle\Model\GatewayConfig:
config:
client_id: '<getenv("TPAY_CLIENT_ID")>'
client_secret: '<getenv("TPAY_CLIENT_SECRET")>'
cards_api: '<getenv("TPAY_CARDS_API")>'
type: 'card'
production_mode: false
gateway_tpay_blik:
Expand Down
99 changes: 97 additions & 2 deletions tests/mockoon_tpay.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\": \"[email protected]\",\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\": \"[email protected]\",\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\": \"<[email protected]>\",\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\": \"<https://secure.tpay.com/?title=TR-BRA-CCP1S9X&uid=01HXCS9KVQBDZDDWDHP1TZKJ1K>\"\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
Expand Down Expand Up @@ -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\": \"[email protected]\",\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": [
Expand All @@ -75,6 +166,10 @@
{
"type": "route",
"uuid": "5b0daede-d7b8-4329-8ee4-cfedffc699d0"
},
{
"type": "route",
"uuid": "0b6be9e5-c227-4fa9-a8c5-fc7a0daf9881"
}
],
"proxyMode": false,
Expand Down

0 comments on commit 348cf53

Please sign in to comment.