Skip to content

Commit

Permalink
Merge pull request #197 from mewebstudio/196-albaraka-posnet-yanlis-u…
Browse files Browse the repository at this point in the history
…rllere-istek-gonderiyor

fix issue #196 PosNetV1 sending request to wrong url
  • Loading branch information
nuryagdym authored Apr 1, 2024
2 parents 831a1ff + 7685a93 commit 15e82bb
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/Gateways/PosNetV1Pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function orderHistory(array $order): PosInterface
*/
protected function send($contents, string $txType, string $paymentModel, ?string $url = null): array
{
$url = $this->getApiURL();
$url = $this->getApiURL($txType);
$this->logger->debug('sending request', ['url' => $url]);

if (!is_string($contents)) {
Expand Down
83 changes: 58 additions & 25 deletions tests/Unit/Gateways/PosNetV1PosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ protected function setUp(): void
parent::setUp();

$this->config = [
'name' => 'Albaraka',
'class' => PosNetV1Pos::class,
'gateway_endpoints' => [
'payment_api' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc',
'gateway_3d' => 'https://epostest.albarakaturk.com.tr/ALBSecurePaymentUI/SecureProcess/SecureVerification.aspx',
'name' => 'Albaraka',
'class' => PosNetV1Pos::class,
'gateway_endpoints' => [
'payment_api' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc',
'gateway_3d' => 'https://epostest.albarakaturk.com.tr/ALBSecurePaymentUI/SecureProcess/SecureVerification.aspx',
],
];

Expand Down Expand Up @@ -145,11 +145,12 @@ public function testGetApiURL(string $txType, string $mappedTxType, string $expe
*/
public function testGet3DFormData(
bool $isWithCard
): void {
$card = $isWithCard ? $this->card : null;
$order = ['id' => '124'];
): void
{
$card = $isWithCard ? $this->card : null;
$order = ['id' => '124'];
$paymentModel = PosInterface::MODEL_3D_SECURE;
$txType = PosInterface::TX_TYPE_PAY_AUTH;
$txType = PosInterface::TX_TYPE_PAY_AUTH;

$this->requestMapperMock->expects(self::once())
->method('create3DFormData')
Expand Down Expand Up @@ -202,14 +203,18 @@ public function testMake3DPayment(
'create3DPaymentRequestData',
];
if ($is3DSuccess) {
$this->requestMapperMock->expects(self::once())
->method('mapTxType')
->with($txType)
->willReturn('Sale');
$this->requestMapperMock->expects(self::once())
->method('create3DPaymentRequestData')
->with($this->account, $order, $txType, $request->request->all())
->willReturn($create3DPaymentRequestData);
$this->prepareClient(
$this->httpClientMock,
'response-body',
$this->config['gateway_endpoints']['payment_api'],
'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Sale',
[
'headers' => [
'Content-Type' => 'application/json',
Expand Down Expand Up @@ -270,11 +275,17 @@ public function testMake3DPayPayment(): void
/**
* @dataProvider makeRegularPaymentDataProvider
*/
public function testMakeRegularPayment(array $order, string $txType, string $apiUrl): void
public function testMakeRegularPayment(array $order, string $txType, string $mappedTxType, string $apiUrl): void
{
$account = $this->pos->getAccount();
$card = $this->card;

$this->requestMapperMock->expects(self::once())
->method('mapTxType')
->with($txType)
->willReturn($mappedTxType);

$this->requestMapperMock->expects(self::once())
->method('createNonSecurePaymentRequestData')
->with($account, $order, $txType, $card)
->willReturn(['createNonSecurePaymentRequestData']);
Expand Down Expand Up @@ -316,6 +327,11 @@ public function testMakeRegularPostAuthPayment(array $order, string $apiUrl): vo
$account = $this->pos->getAccount();
$txType = PosInterface::TX_TYPE_PAY_POST_AUTH;

$this->requestMapperMock->expects(self::once())
->method('mapTxType')
->with($txType)
->willReturn('Capture');

$this->requestMapperMock->expects(self::once())
->method('createNonSecurePostAuthPaymentRequestData')
->with($account, $order)
Expand Down Expand Up @@ -358,7 +374,12 @@ public function testMakeRegularPostAuthPayment(array $order, string $apiUrl): vo
public function testStatusRequest(array $order, string $apiUrl): void
{
$account = $this->pos->getAccount();
$txType = PosInterface::TX_TYPE_STATUS;
$txType = PosInterface::TX_TYPE_STATUS;

$this->requestMapperMock->expects(self::once())
->method('mapTxType')
->with($txType)
->willReturn('TransactionInquiry');

$this->requestMapperMock->expects(self::once())
->method('createStatusRequestData')
Expand Down Expand Up @@ -402,7 +423,12 @@ public function testStatusRequest(array $order, string $apiUrl): void
public function testCancelRequest(array $order, string $apiUrl): void
{
$account = $this->pos->getAccount();
$txType = PosInterface::TX_TYPE_CANCEL;
$txType = PosInterface::TX_TYPE_CANCEL;

$this->requestMapperMock->expects(self::once())
->method('mapTxType')
->with($txType)
->willReturn('Reverse');

$this->requestMapperMock->expects(self::once())
->method('createCancelRequestData')
Expand Down Expand Up @@ -445,7 +471,12 @@ public function testCancelRequest(array $order, string $apiUrl): void
public function testRefundRequest(array $order, string $apiUrl): void
{
$account = $this->pos->getAccount();
$txType = PosInterface::TX_TYPE_REFUND;
$txType = PosInterface::TX_TYPE_REFUND;

$this->requestMapperMock->expects(self::once())
->method('mapTxType')
->with($txType)
->willReturn('Return');

$this->requestMapperMock->expects(self::once())
->method('createRefundRequestData')
Expand Down Expand Up @@ -529,7 +560,7 @@ public static function getApiURLDataProvider(): iterable

public static function make3DPaymentDataProvider(): array
{
$dataSamples = iterator_to_array(PosNetV1PosResponseDataMapperTest::threeDPaymentDataProvider());
$dataSamples = iterator_to_array(PosNetV1PosResponseDataMapperTest::threeDPaymentDataProvider());

return [
'auth_fail' => [
Expand Down Expand Up @@ -574,18 +605,20 @@ public static function makeRegularPaymentDataProvider(): array
{
return [
[
'order' => [
'order' => [
'id' => '2020110828BC',
],
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc',
'txType' => PosInterface::TX_TYPE_PAY_AUTH,
'mappedTxType' => 'Sale',
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Sale',
],
[
'order' => [
'order' => [
'id' => '2020110828BC',
],
'txType' => PosInterface::TX_TYPE_PAY_PRE_AUTH,
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc',
'txType' => PosInterface::TX_TYPE_PAY_PRE_AUTH,
'mappedTxType' => 'Auth',
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Auth',
],
];
}
Expand All @@ -597,7 +630,7 @@ public static function makeRegularPostAuthPaymentDataProvider(): array
'order' => [
'id' => '2020110828BC',
],
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc',
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Capture',
],
];
}
Expand All @@ -609,7 +642,7 @@ public static function statusRequestDataProvider(): array
'order' => [
'id' => '2020110828BC',
],
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc',
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/TransactionInquiry',
],
];
}
Expand All @@ -621,7 +654,7 @@ public static function cancelRequestDataProvider(): array
'order' => [
'id' => '2020110828BC',
],
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc',
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Reverse',
],
];
}
Expand All @@ -633,7 +666,7 @@ public static function refundRequestDataProvider(): array
'order' => [
'id' => '2020110828BC',
],
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc',
'api_url' => 'https://epostest.albarakaturk.com.tr/ALBMerchantService/MerchantJSONAPI.svc/Return',
],
];
}
Expand Down

0 comments on commit 15e82bb

Please sign in to comment.