Skip to content

Commit

Permalink
void
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Oct 14, 2024
1 parent d041e6d commit 9ee8d62
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Omnipay\Gomypay\Message\FetchTransactionRequest;
use Omnipay\Gomypay\Message\GetPaymentInfoRequest;
use Omnipay\Gomypay\Message\PurchaseRequest;
use Omnipay\Gomypay\Message\VoidRequest;
use Omnipay\Gomypay\Traits\HasGomypay;

/**
Expand Down Expand Up @@ -51,6 +52,11 @@ public function fetchTransaction(array $options = [])
return $this->createRequest(FetchTransactionRequest::class, $options);
}

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

public function getPaymentInfo(array $options = [])
{
return $this->createRequest(GetPaymentInfoRequest::class, $options);
Expand Down
2 changes: 1 addition & 1 deletion src/Message/FetchTransactionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function sendData($data)
$response = $this->httpClient->request(
'POST',
$this->getUrl('CallOrder.aspx'),
['content-type' => 'application/json'],
['content-type' => 'application/x-www-form-urlencoded'],
http_build_query($data)
);
$data = json_decode((string) $response->getBody(), true);
Expand Down
62 changes: 62 additions & 0 deletions src/Message/VoidRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Omnipay\Gomypay\Message;

use Omnipay\Gomypay\Traits\HasGomypay;
use Omnipay\Gomypay\Traits\HasOrderNo;

class VoidRequest extends AbstractRequest
{
use HasGomypay;
use HasOrderNo;

public function getGoodsReturn()
{
return $this->getParameter('Goods_Return');
}

/**
* 退貨註記請填 1(申請退貨)
*/
public function setGoodsRetrun($value)
{
return $this->setParameter('Goods_Return', $value);
}

public function getGoodsReturnReason()
{
return $this->getParameter('Goods_Return_Reason');
}

/**
* 退貨原因
*/
public function setGoodsReturnReason($value)
{
return $this->setParameter('Goods_Return_Reason', $value);
}

public function getData()
{
return [
'Order_No' => $this->getTransactionId(),
'CustomerId' => $this->getCustomerId(),
'Str_Check' => $this->getStrCheck(),
'Goods_Return' => $this->getGoodsReturn() ?: 1,
'Goods_Return_Reason' => $this->getGoodsReturnReason() ?: '退貨',
];
}

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

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

namespace Omnipay\Gomypay\Message;

class VoidResponse extends AbstractResponse
{
public function isSuccessful()
{
return false;
}

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

public function getMessage()
{
return $this->data['ret_msg'];
}
}
38 changes: 38 additions & 0 deletions tests/Message/VoidRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Omnipay\Gomypay\Tests\Message;

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

class VoidRequestTest extends TestCase
{
/**
* @var VoidRequest
*/
private $request;

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

$this->request = new VoidRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize([
'CustomerId' => '42816104A05',
'Str_Check' => '2b1bef9d8ab6a81e9a2739c6ecc64ef8',
'test_mode' => true,

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

public function testGetData()
{
$this->setMockHttpResponse('VoidSuccess.txt');
$response = $this->request->send();

$this->assertFalse($response->isSuccessful());
$this->assertEquals('申請退貨完成', $response->getMessage());
$this->assertEquals('1', $response->getCode());
}
}
7 changes: 7 additions & 0 deletions tests/Mock/VoidSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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":"申請退貨完成"}

0 comments on commit 9ee8d62

Please sign in to comment.