Skip to content

Commit

Permalink
get payment info
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Oct 13, 2024
1 parent f6a2322 commit 94d5aa4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 4 deletions.
28 changes: 27 additions & 1 deletion src/Message/GetPaymentInfoRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,41 @@

namespace Omnipay\Gomypay\Message;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\InvalidResponseException;
use Omnipay\Gomypay\Traits\HasGomypay;

class GetPaymentInfoRequest extends AbstractRequest
{
use HasGomypay;

public function getData()
{
return $this->httpRequest->request->all();
return $this->httpRequest->query->all();
}

/**
* @throws InvalidRequestException
* @throws InvalidResponseException
*/
public function sendData($data)
{
$data = array_merge($data, [
'CustomerId' => $this->getCustomerId(),
'Amount' => (int) $this->getAmount(),
'Str_Check' => $this->getStrCheck(),
]);

$keys = ['result', 'e_orderno', 'CustomerId', 'Amount', 'OrderID', 'Str_Check'];
$plainText = '';
foreach ($keys as $key) {
$plainText .= $data[$key];
}
$hash = md5($plainText);
if (! hash_equals($hash, $data['str_check'])) {
throw new InvalidResponseException('Invalid check');
}

return $this->response = new GetPaymentInfoResponse($this, $data);
}
}
22 changes: 21 additions & 1 deletion src/Message/GetPaymentInfoResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ class GetPaymentInfoResponse extends AbstractResponse
{
public function isSuccessful()
{
// TODO: Implement isSuccessful() method.
return false;
}

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'];
}
}
3 changes: 2 additions & 1 deletion src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ public function getCvsData()
{
$eReturn = $this->getEReturn();
$strCheck = $eReturn ? $this->getStrCheck() : null;
$returnUrl = $this->getPaymentInfoUrl() ?: $this->getReturnUrl();

return [
'Send_Type' => PaymentMethod::CVS,
Expand All @@ -435,7 +436,7 @@ public function getCvsData()
'Buyer_Telm' => $this->getBuyerTelm(),
'Buyer_Mail' => $this->getBuyerMail(),
'Buyer_Memo' => $this->getDescription(),
'Return_url' => $this->getReturnUrl(),
'Return_url' => $returnUrl,
'Callback_Url' => $this->getCallbackUrl(),
'e_return' => $eReturn,
'Str_Check' => $strCheck,
Expand Down
44 changes: 44 additions & 0 deletions tests/Message/GetPaymentInfoRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,48 @@ public function setUp(): void
'Str_Check' => '2b1bef9d8ab6a81e9a2739c6ecc64ef8',
]);
}

public function testGetVirtualAccountData()
{
$this->getHttpRequest()->query->replace([
'Send_Type' => '4',
'result' => '1',
'OrderID' => '2020050700000000001',
'e_orderno' => '2020050701',
'e_payaccount' => '013 - 國泰世華 - 0055600701508856',
'LimitDate' => '2020/07/01',
'ret_msg' => '取號成功',
'str_check' => 'bf577c7a76d440a797c1716aff9c01c9',
]);
$this->request->setAmount('50');
$response = $this->request->send();

$this->assertFalse($response->isSuccessful());
$this->assertEquals('取號成功', $response->getMessage());
$this->assertEquals('1', $response->getCode());
$this->assertEquals('2020050701', $response->getTransactionId());
$this->assertEquals('2020050700000000001', $response->getTransactionReference());
}

public function testGetCvsData()
{
$this->getHttpRequest()->query->replace([
'Send_Type' => '6',
'StoreType' => '3',
'result' => '1',
'OrderID' => '2020050700000000001',
'e_orderno' => '2020050701',
'PinCode' => 'GMPA2018383076',
'ret_msg' => '取號成功',
'str_check' => 'bf577c7a76d440a797c1716aff9c01c9',
]);
$this->request->setAmount('50');
$response = $this->request->send();

$this->assertFalse($response->isSuccessful());
$this->assertEquals('取號成功', $response->getMessage());
$this->assertEquals('1', $response->getCode());
$this->assertEquals('2020050701', $response->getTransactionId());
$this->assertEquals('2020050700000000001', $response->getTransactionReference());
}
}
3 changes: 2 additions & 1 deletion tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public function testGetVirtualAccountData()
public function testGetCvsData()
{
$this->request->setPaymentMethod(PaymentMethod::CVS);
$this->request->setPaymentInfoUrl('https://foo.bar/payment_info_url');
$this->request->setStoreType(3);

$response = $this->request->send();
Expand All @@ -235,7 +236,7 @@ public function testGetCvsData()
'Buyer_Telm' => '0912345678',
'Buyer_Mail' => 'foo@bar.com',
'Buyer_Memo' => 'good to drink',
'Return_url' => 'https://foo.bar/return_url',
'Return_url' => 'https://foo.bar/payment_info_url',
'Callback_Url' => 'https://foo.bar/callback_url',
], $data);
}
Expand Down

0 comments on commit 94d5aa4

Please sign in to comment.