Skip to content

Commit

Permalink
union pay purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Oct 12, 2024
1 parent fcde69d commit 9fef1b4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,19 @@ public function getData()
$expireDate = $card ? $card->getExpiryDate('ym') : $this->getExpireDate();
$cvv = $card ? $card->getCvv() : $this->getCVV();

$transMode = null;
$installment = null;

$paymentMethod = (string) $this->getPaymentMethod();
if ($paymentMethod === '0') {
$transMode = $this->getTransMode() ?: 1;
$installment = $this->getInstallment() ?: 0;
}

$strCheck = $paymentMethod === '1' ? null : $this->getStrCheck();

return array_filter([
'Send_Type' => $this->getPaymentMethod(),
'Send_Type' => $paymentMethod,
'Pay_Mode_No' => $this->getPayModeNo() ?: '2',
'CustomerId' => $this->getCustomerId(),
'Order_No' => $this->getOrderNo(),
Expand All @@ -42,12 +53,12 @@ public function getData()
'CardNo' => $cardNo,
'ExpireDate' => $expireDate,
'CVV' => $cvv,
'TransMode' => $this->getTransMode() ?: 1,
'Installment' => $this->getInstallment() ?: 0,
'TransMode' => $transMode,
'Installment' => $installment,
'Return_url' => $this->getReturnUrl(),
'Callback_Url' => $this->getCallbackUrl(),
'e_return' => $this->getEReturn(),
'Str_Check' => $this->getStrCheck(),
'Str_Check' => $strCheck,
], static function ($value) {
return $value !== null;
});
Expand Down
61 changes: 61 additions & 0 deletions tests/Message/PurchaseRequestForUnionPayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Omnipay\Gomypay\Tests\Message;

use Omnipay\Gomypay\Message\PurchaseRequest;
use Omnipay\Tests\TestCase;

class PurchaseRequestForUnionPayTest extends TestCase
{
/**
* @var PurchaseRequest
*/
private $request;

public function setUp(): void
{
parent::setUp();

$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize([
'test_mode' => true,
'transaction_id' => '2018001',
'amount' => '1000',
'description' => 'good to drink',
'payment_method' => 1,
'return_url' => 'https://foo.bar/return_url',
'notify_url' => 'https://foo.bar/callback_url',

'CustomerId' => '80013554',
'Buyer_Name' => 'foo',
'Buyer_Telm' => '0912345678',
'Buyer_Mail' => 'foo@bar.com',
]);
}

public function testGetData()
{
$response = $this->request->send();
$data = $response->getData();

$this->assertFalse($response->isSuccessful());
$this->assertEquals('https://n.gomypay.asia/TestShuntClass.aspx', $response->getRedirectUrl());
$this->assertEquals('POST', $response->getRedirectMethod());
$this->assertEquals('2018001', $response->getTransactionId());

$this->assertEquals([
'Send_Type' => 1,
'Pay_Mode_No' => 2,
'CustomerId' => '80013554',
'Order_No' => '2018001',
'Amount' => '1000',
'TransCode' => '00',
'Buyer_Name' => 'foo',
'Buyer_Telm' => '0912345678',
'Buyer_Mail' => 'foo@bar.com',
'Buyer_Memo' => 'good to drink',
'Return_url' => 'https://foo.bar/return_url',
'Callback_Url' => 'https://foo.bar/callback_url',
], $data);
}
}

0 comments on commit 9fef1b4

Please sign in to comment.