Skip to content

Commit

Permalink
test complete purchase send
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Feb 10, 2024
1 parent db88ef3 commit 7123351
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Message/XWallet/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Omnipay\ePays\Message\XWallet;

use Omnipay\ePays\Traits\XWallet\HasEPays;

class CompletePurchaseRequest extends AbstractRequest
{
use HasEPays;

public function getData()
{
return json_decode($this->httpRequest->getContent(), true);
}

public function sendData($data)
{
}
}
6 changes: 6 additions & 0 deletions src/XWalletGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Omnipay\ePays;

use Omnipay\Common\AbstractGateway;
use Omnipay\ePays\Message\XWallet\CompletePurchaseRequest;
use Omnipay\ePays\Message\XWallet\PurchaseRequest;
use Omnipay\ePays\Traits\XWallet\HasEPays;

Expand Down Expand Up @@ -31,4 +32,9 @@ public function purchase(array $options = [])
{
return $this->createRequest(PurchaseRequest::class, $options);
}

public function completePurchase(array $options = [])
{
return $this->createRequest(CompletePurchaseRequest::class, $options);
}
}
42 changes: 42 additions & 0 deletions tests/Message/XWallet/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Omnipay\ePays\Tests\Message\XWallet;

use Omnipay\ePays\Encryptor;
use Omnipay\ePays\Message\XWallet\CompletePurchaseRequest;
use Omnipay\Tests\TestCase;
use Symfony\Component\HttpFoundation\Request as HttpRequest;

class CompletePurchaseRequestTest extends TestCase
{
private $initialize = [
'HashKey' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'HashIV' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
];

public function testGetData(): void
{
$encryptor = new Encryptor($this->initialize['HashKey'], $this->initialize['HashIV']);
$data = $encryptor->encrypt([
'FirmOrderNo' => 'test202309011123001',
'PayNo' => '460199********8103',
'PriceReal' => 100,
]);
$httpRequest = new HttpRequest([], [], [], [], [], [], json_encode([
'state' => '1',
'code' => '200',
'msg' => '交易成功',
'data' => $data,
]));
$httpRequest->setMethod('POST');
$request = new CompletePurchaseRequest($this->getHttpClient(), $httpRequest);
$request->initialize(array_merge($this->initialize, []));

self::assertEquals([
'state' => '1',
'code' => '200',
'msg' => '交易成功',
'data' => $data,
], $request->getData());
}
}

0 comments on commit 7123351

Please sign in to comment.