Skip to content

Commit

Permalink
fetch transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Oct 14, 2024
1 parent 3f81a9d commit d97d9a7
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 22 deletions.
6 changes: 6 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Omnipay\Common\AbstractGateway;
use Omnipay\Gomypay\Message\AcceptNotificationRequest;
use Omnipay\Gomypay\Message\CompletePurchaseRequest;
use Omnipay\Gomypay\Message\FetchTransactionRequest;
use Omnipay\Gomypay\Message\PurchaseRequest;
use Omnipay\Gomypay\Traits\HasGomypay;

Expand Down Expand Up @@ -44,6 +45,11 @@ public function acceptNotification(array $options = [])
return $this->createRequest(AcceptNotificationRequest::class, $options);
}

public function fetchTransaction(array $options = [])
{
return $this->createRequest(FetchTransactionRequest::class, $options);
}

public function getPaymentInfo(array $options = [])
{
return $this->createRequest(GetPaymentInfoRequest::class, $options);
Expand Down
10 changes: 5 additions & 5 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

abstract class AbstractRequest extends BaseAbstractRequest
{
protected $liveEndpoint = 'https://n.gomypay.asia/ShuntClass.aspx';
protected $host = 'https://n.gomypay.asia/';

protected $testEndpoint = 'https://n.gomypay.asia/TestShuntClass.aspx';

public function getEndpoint()
public function getUrl($uri)
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
return $this->getTestMode()
? $this->host.'Test'.$uri
: $this->host.$uri;
}
}
34 changes: 34 additions & 0 deletions src/Message/FetchTransactionRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Omnipay\Gomypay\Message;

use Omnipay\Gomypay\Traits\HasGomypay;

class FetchTransactionRequest extends AbstractRequest
{
use HasGomypay;

public function getData()
{
$this->validate('transactionId');

return [
'Order_No' => $this->getTransactionId(),
'CustomerId' => $this->getCustomerId(),
'Str_Check' => $this->getStrCheck(),
];
}

public function sendData($data)
{
$response = $this->httpClient->request(
'POST',
$this->getUrl('CallOrder.aspx'),
['content-type' => 'application/json'],
http_build_query($data)
);
$data = json_decode((string) $response->getBody(), true);

return $this->response = new FetchTransactionResponse($this, $data);
}
}
31 changes: 31 additions & 0 deletions src/Message/FetchTransactionResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Omnipay\Gomypay\Message;

class FetchTransactionResponse extends AbstractResponse
{
public function isSuccessful()
{
return (int) $this->getCode() === 1;
}

public function getCode()
{
return $this->data['result'];
}

public function getMessage()
{
return $this->data['ret_msg'];
}

public function getTransactionId()
{
return $this->data['e_orderno'];
}

public function getTransactionReference()
{
return $this->data['OrderID'];
}
}
16 changes: 2 additions & 14 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Gomypay\PaymentMethod;
use Omnipay\Gomypay\Traits\HasGomypay;
use Omnipay\Gomypay\Traits\HasOrderNo;

class PurchaseRequest extends AbstractRequest
{
use HasGomypay;
use HasOrderNo;

public function getSendType()
{
Expand Down Expand Up @@ -36,20 +38,6 @@ public function setPayModeNo($value)
return $this->setParameter('Pay_Mode_No', $value);
}

public function getOrderNo()
{
return $this->getTransactionId();
}

/**
* 交易單號,如無則自動帶入系統預設交易單號
* 若使用系統預設交易畫面,交易單號不可為無
*/
public function setOrderNo($value)
{
return $this->setTransactionId($value);
}

public function getAmount()
{
return parent::getAmount();
Expand Down
4 changes: 1 addition & 3 deletions src/Message/PurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public function isRedirect()

public function getRedirectUrl()
{
return $this->request->getTestMode()
? 'https://n.gomypay.asia/TestShuntClass.aspx'
: 'https://n.gomypay.asia/ShuntClass.aspx';
return $this->request->getUrl('ShuntClass.aspx');
}

public function getRedirectMethod()
Expand Down
20 changes: 20 additions & 0 deletions src/Traits/HasOrderNo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Omnipay\Gomypay\Traits;

trait HasOrderNo
{
public function getOrderNo()
{
return $this->getTransactionId();
}

/**
* 交易單號,如無則自動帶入系統預設交易單號
* 若使用系統預設交易畫面,交易單號不可為無
*/
public function setOrderNo($value)
{
return $this->setTransactionId($value);
}
}
34 changes: 34 additions & 0 deletions tests/Message/FetchTransactionRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Omnipay\Gomypay\Tests\Message;

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

class FetchTransactionRequestTest extends TestCase
{
/**
* @var FetchTransactionRequest
*/
private $request;

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

$this->request = new FetchTransactionRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize([
'CustomerId' => '83759795',
'Str_Check' => 'tak8ebh0qg1irbs72t1a34f2qdc7jyc7',
'test_mode' => true,

'transaction_id' => '2024101311',
]);
}

public function testGetData()
{
$this->setMockHttpResponse('FetchTransactionSuccess.txt');
var_dump($this->request->send());
}
}
39 changes: 39 additions & 0 deletions tests/Mock/FetchTransactionSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
HTTP/1.1 200 OK
Server: Apache
Date: Sun, 11 May 2014 21:17:31 GMT
Content-Type: application/json; charset=utf-8
Status: 200 OK

{
"result": "1",
"ret_msg": "已繳費",
"OrderID": "2019012300000000569",
"e_Cur": "NT",
"e_money": "10000",
"PayAmount": "10000",
"e_date": "20190123",
"e_time": "18:37:59",
"p_date": "20190123",
"p_time": "18:42:17",
"e_orderno": "AH15482399052114",
"e_no": "42816104A05",
"e_outlay": "26",
"bankname": "",
"avcode": "",
"Buyer_Name": "User",
"Buyer_Mail": "paymoney159@gmail.com",
"Buyer_Telm": "0900000000",
"Buyer_Memo": "此為商城虛擬商品購買,並非實體商品交易,請勿受騙上當,並請勿代他人繳款儲值,小心觸法",
"Creditcard_No": "",
"Installment": "0",
"Shop_PaymentCode": "1610A8259J3291",
"Virtual_Account": "",
"e_PayInfo": "",
"Send_Type": "6",
"Goods_Return": "0",
"Goods_Return_Statu": "",
"pay_result": "1",
"LimitDate": "20190123",
"Market_ID": "FM",
"Shop_Store_Name": "中壢興廣店(桃園市中壢區新中北路二段489號)"
}

0 comments on commit d97d9a7

Please sign in to comment.