|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/** |
| 3 | + * Copyright © MultiSafepay, Inc. All rights reserved. |
| 4 | + * See DISCLAIMER.md for disclaimer details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace MultiSafepay\Tests\Api\Integration\Transactions; |
| 8 | + |
| 9 | +use MultiSafepay\Api\Transactions\TransactionResponse; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +class TransactionResponseTest extends TestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * Test if getGatewayId will return a single gateway ID when only one payment method is used |
| 16 | + * |
| 17 | + * @return void |
| 18 | + */ |
| 19 | + public function testGetGatewayIdReturnsSingleGatewayIdWhenOnlyOnePaymentMethodIsUsed(): void |
| 20 | + { |
| 21 | + $transactionResponse = $this->createTransactionResponseWithPaymentMethods([ |
| 22 | + ['type' => 'VISA'], |
| 23 | + ]); |
| 24 | + |
| 25 | + $this->assertEquals('VISA', $transactionResponse->getGatewayId()); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Test if getGatewayId will return multiple gateway IDs when multiple payment methods are used |
| 30 | + * |
| 31 | + * @return void |
| 32 | + */ |
| 33 | + public function testGetGatewayIdReturnsMultipleGatewayIdsWhenMultiplePaymentMethodsAreUsed(): void |
| 34 | + { |
| 35 | + $transactionResponse = $this->createTransactionResponseWithPaymentMethods([ |
| 36 | + ['type' => 'VISA'], |
| 37 | + ['type' => 'MASTERCARD'], |
| 38 | + ]); |
| 39 | + |
| 40 | + $this->assertEquals('VISA, MASTERCARD', $transactionResponse->getGatewayId()); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Test if getGatewayId will return the coupon brand when a coupon payment method is used |
| 45 | + * |
| 46 | + * @return void |
| 47 | + */ |
| 48 | + public function testGetGatewayIdReturnsCouponBrandWhenCouponPaymentMethodIsUsed(): void |
| 49 | + { |
| 50 | + $transactionResponse = $this->createTransactionResponseWithPaymentMethods([ |
| 51 | + ['type' => 'COUPON', 'coupon_brand' => 'GIFT'], |
| 52 | + ]); |
| 53 | + |
| 54 | + $this->assertEquals('GIFT', $transactionResponse->getGatewayId()); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Test if getGatewayId will return unknown when a coupon payment method is used without a brand |
| 59 | + * |
| 60 | + * @return void |
| 61 | + */ |
| 62 | + public function testGetGatewayIdReturnsUnknownWhenCouponPaymentMethodIsUsedWithoutBrand(): void |
| 63 | + { |
| 64 | + $transactionResponse = $this->createTransactionResponseWithPaymentMethods([ |
| 65 | + ['type' => 'COUPON'], |
| 66 | + ]); |
| 67 | + |
| 68 | + $this->assertEquals('unknown', $transactionResponse->getGatewayId()); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Retrieve a TransactionResponse with the provided payment methods |
| 73 | + * |
| 74 | + * @param array $paymentMethods |
| 75 | + * @return TransactionResponse |
| 76 | + */ |
| 77 | + private function createTransactionResponseWithPaymentMethods(array $paymentMethods): TransactionResponse |
| 78 | + { |
| 79 | + $data = ['payment_methods' => $paymentMethods]; |
| 80 | + return new TransactionResponse($data); |
| 81 | + } |
| 82 | +} |
0 commit comments