Skip to content

Commit

Permalink
get amount directly
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Mar 23, 2023
1 parent 2a6698c commit 0b84766
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 23 deletions.
5 changes: 0 additions & 5 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function getDefaultParameters()
}

/**
* @param array $options
* @return RequestInterface
*/
public function purchase(array $options = [])
Expand All @@ -53,7 +52,6 @@ public function purchase(array $options = [])
}

/**
* @param array $options
* @return RequestInterface
*/
public function completePurchase(array $options = [])
Expand All @@ -62,7 +60,6 @@ public function completePurchase(array $options = [])
}

/**
* @param array $options
* @return RequestInterface|NotificationInterface
*/
public function acceptNotification(array $options = [])
Expand All @@ -71,7 +68,6 @@ public function acceptNotification(array $options = [])
}

/**
* @param array $options
* @return RequestInterface
*/
public function fetchTransaction(array $options = [])
Expand All @@ -80,7 +76,6 @@ public function fetchTransaction(array $options = [])
}

/**
* @param array $options
* @return RequestInterface
*/
public function refund(array $options = [])
Expand Down
1 change: 0 additions & 1 deletion src/Message/FetchTransactionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function sendData($data)
}

/**
* @param $data
* @return array
*
* @throws RtnException
Expand Down
16 changes: 10 additions & 6 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\ECPay\Item;
use Omnipay\ECPay\Traits\HasAmount;
use Omnipay\ECPay\Traits\HasATMFields;
use Omnipay\ECPay\Traits\HasATMOrCVSOrBARCODEFields;
use Omnipay\ECPay\Traits\HasCreditFields;
Expand All @@ -32,6 +33,7 @@ class PurchaseRequest extends AbstractRequest
use HasATMFields;
use HasCVSOrBARCODEFields;
use HasATMOrCVSOrBARCODEFields;
use HasAmount;

protected $liveEndpoint = 'https://payment.ecpay.com.tw/Cashier/AioCheckOut/V5';

Expand Down Expand Up @@ -125,12 +127,14 @@ private function prepareItems()
$currency = $this->getCurrency() ?: 'TWD';

if (! $items) {
return [new Item([
'Name' => $this->getDescription(),
'Price' => $this->getAmount(),
'Currency' => $currency,
'Quantity' => 1,
])];
return [
new Item([
'Name' => $this->getDescription(),
'Price' => $this->getAmount(),
'Currency' => $currency,
'Quantity' => 1,
]),
];
}

return array_map(static function ($item) use ($currency) {
Expand Down
2 changes: 2 additions & 0 deletions src/Message/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Ecpay\Sdk\Exceptions\RtnException;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\ECPay\Traits\HasAmount;
use Omnipay\ECPay\Traits\HasDefaults;
use Omnipay\ECPay\Traits\HasECPay;
use Omnipay\ECPay\Traits\HasMerchantTradeNo;
Expand All @@ -15,6 +16,7 @@ class RefundRequest extends AbstractRequest
use HasDefaults;
use HasMerchantTradeNo;
use HasTotalAmount;
use HasAmount;

public function setTradeNo($value)
{
Expand Down
11 changes: 11 additions & 0 deletions src/Traits/HasAmount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Omnipay\ECPay\Traits;

trait HasAmount
{
public function getAmount()
{
return $this->getParameter('amount');
}
}
2 changes: 0 additions & 2 deletions tests/Message/AcceptNotificationRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public function testGetData()

/**
* @depends testGetData
*
* @param $results
*/
public function testSendData($results)
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Message/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public function testGetData()

/**
* @depends testGetData
*
* @param $result
*/
public function testSendData($result)
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Message/FetchTransactionRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public function testGetData()

/**
* @depends testGetData
*
* @param $result
*/
public function testSendData($result)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/RefundRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testGetData()
'MerchantTradeNo' => '2821567410556',
'TradeNo' => '1909021549160081',
'Action' => 'R',
'TotalAmount' => '1000.00',
'TotalAmount' => '1000',
], $request->getData());
}
}
2 changes: 1 addition & 1 deletion tests/Message/VoidRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testGetData()
'MerchantTradeNo' => '2821567410556',
'TradeNo' => '1909021549160081',
'Action' => 'N',
'TotalAmount' => '1000.00',
'TotalAmount' => '1000',
], $request->getData());
}
}
3 changes: 0 additions & 3 deletions tests/Stubs/StubGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
class StubGateway extends Gateway
{
/**
* @param array $options
* @return RequestInterface
*/
public function fetchTransaction(array $options = [])
Expand All @@ -17,7 +16,6 @@ public function fetchTransaction(array $options = [])
}

/**
* @param array $options
* @return RequestInterface
*/
public function refund(array $options = [])
Expand All @@ -26,7 +24,6 @@ public function refund(array $options = [])
}

/**
* @param array $options
* @return RequestInterface
*/
public function void(array $options = [])
Expand Down

0 comments on commit 0b84766

Please sign in to comment.