Skip to content

Commit

Permalink
Merge 572807b into c23c3ce
Browse files Browse the repository at this point in the history
  • Loading branch information
paypay-ayas committed Sep 28, 2020
2 parents c23c3ce + 572807b commit b51f24a
Show file tree
Hide file tree
Showing 16 changed files with 459 additions and 54 deletions.
20 changes: 20 additions & 0 deletions mock/mappings/PendingPaymentCancel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"request": {
"method": "DELETE",
"urlPattern": "^\\/v1\\/requestOrder\\/.*[0-9a-zA-Z].*$"
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"resultInfo": {
"code": "REQUEST_ACCEPTED",
"message": "Request accepted",
"codeId": "08100001"
},
"data": null
}
}
}
30 changes: 30 additions & 0 deletions mock/mappings/PendingPaymentCreate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"request": {
"method": "POST",
"url": "/v1/requestOrder"
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"resultInfo": {
"code": "SUCCESS",
"message": "Success",
"codeId": "08100001"
},
"data": {
"merchantPaymentId": "TESTMERCH_PAY_ID5f55c201d6359",
"userAuthorizationId": "SAME-USER-AUTH-ID-PROVIDED_BY_YOU",
"amount": {
"amount": 12,
"currency": "JPY"
},
"orderItems": [],
"expiryDate": 1599477346,
"requestedAt": 1599455745
}
}
}
}
36 changes: 36 additions & 0 deletions mock/mappings/PendingPaymentDetails.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"request": {
"method": "GET",
"urlPattern": "^\\/v1\\/requestOrder\\/.*[0-9a-zA-Z].*$"
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"resultInfo": {
"code": "SUCCESS",
"message": "Success",
"codeId": "08100001"
},
"data": {
"merchantPaymentId": "MERCHANT_PAYMENT_IDENTIFIER",
"userAuthorizationId": "USER_AUTHORIZATION",
"amount": {
"amount": 15,
"currency": "JPY"
},
"orderItems": [],
"status": "COMPLETED",
"requestedAt": 1601281573,
"refunds": {
"data": []
},
"expiryDate": 1601303174,
"paymentId": "PAYPAY_PAYMENT_IDENTIFIER",
"acceptedAt": 1601281610
}
}
}
}
31 changes: 31 additions & 0 deletions mock/mappings/PendingPaymentRefundCreate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"request": {
"method": "POST",
"url": "/v1/requestOrder/refunds"
},
"response": {
"status": 201,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": {
"resultInfo": {
"code": "SUCCESS",
"message": "Success",
"codeId": "08100001"
},
"data": {
"status": "CREATED",
"acceptedAt": 1601280078,
"merchantRefundId": "TESTREFUNDID",
"paymentId": "PAYPAY-PAYMENTID",
"amount": {
"amount": 2,
"currency": "JPY"
},
"requestedAt": 1601280078,
"assumeMerchant": "YOURMERCHANTID"
}
}
}
}
2 changes: 1 addition & 1 deletion mock/mappings/createPayment.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"request": {
"method": "POST",
"url": "/v2/payments"
"urlPath": "/v2/payments"
},
"response": {
"status": 201,
Expand Down
71 changes: 36 additions & 35 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true">
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-php" target="./build/cov/clover.xml"/>
</logging>
<testsuites>
<testsuite name="Core Classes">
<file> tests/CoreClassesTest.php</file>
</testsuite>
<testsuite name="Payloads">
<file> tests/PayloadsTest.php</file>
</testsuite>
<testsuite name="QR Code">
<file> tests/QrTest.php</file>
</testsuite>
<testsuite name="Payments">
<file> tests/PaymentTest.php</file>
<file> tests/PreAuthTest.php</file>
<file> tests/ContinuousPaymentTest.php</file>
<file> tests/RefundTest.php</file>
</testsuite>
<testsuite name="User">
<file>tests/PipelinedAccountLinkTest.php</file>
<file> tests/UserTest.php</file>
<file> tests/WalletTest.php </file>
</testsuite>
<testsuite name="Housekeeping">
<file> tests/ZCleanupTest.php</file>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<php outputFile="./build/cov/clover.xml"/>
</report>
</coverage>
<logging/>
<testsuites>
<testsuite name="Core Classes">
<file> tests/CoreClassesTest.php</file>
</testsuite>
<testsuite name="Payloads">
<file> tests/PayloadsTest.php</file>
</testsuite>
<testsuite name="QR Code">
<file> tests/QrTest.php</file>
</testsuite>
<testsuite name="Payments">
<file> tests/PaymentTest.php</file>
<file> tests/PreAuthTest.php</file>
<file> tests/PendingPaymentTest.php</file>
<file> tests/ContinuousPaymentTest.php</file>
<file> tests/RefundTest.php</file>
</testsuite>
<testsuite name="User">
<file>tests/PipelinedAccountLinkTest.php</file>
<file> tests/UserTest.php</file>
<file> tests/WalletTest.php </file>
</testsuite>
<testsuite name="Housekeeping">
<file> tests/ZCleanupTest.php</file>
</testsuite>
</testsuites>
</phpunit>
38 changes: 38 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true">
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-php" target="./build/cov/clover.xml"/>
</logging>
<testsuites>
<testsuite name="Core Classes">
<file> tests/CoreClassesTest.php</file>
</testsuite>
<testsuite name="Payloads">
<file> tests/PayloadsTest.php</file>
</testsuite>
<testsuite name="QR Code">
<file> tests/QrTest.php</file>
</testsuite>
<testsuite name="Payments">
<file> tests/PaymentTest.php</file>
<file> tests/PreAuthTest.php</file>
<file> tests/PendingPaymentTest.php</file>
<file> tests/ContinuousPaymentTest.php</file>
<file> tests/RefundTest.php</file>
</testsuite>
<testsuite name="User">
<file>tests/PipelinedAccountLinkTest.php</file>
<file> tests/UserTest.php</file>
<file> tests/WalletTest.php </file>
</testsuite>
<testsuite name="Housekeeping">
<file> tests/ZCleanupTest.php</file>
</testsuite>
</testsuites>
</phpunit>
70 changes: 63 additions & 7 deletions src/Controllers/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PayPay\OpenPaymentAPI\Controller;

use CreatePendingPaymentPayload;
use \Firebase\JWT\JWT;
use PayPay\OpenPaymentAPI\Models\CapturePaymentAuthPayload;
use PayPay\OpenPaymentAPI\Models\CreatePaymentPayload;
Expand Down Expand Up @@ -77,18 +78,44 @@ public function createContinuousPayment($payload)
return $this->doCall('post',$url,$data,$options);

}
/**
* Create a direct debit payment and start the money transfer.
*
* @param CreatePendingPaymentPayload $payload SDK payload object
* @return mixed
*/
public function createPendingPayment($payload)
{
if (!($payload instanceof CreatePendingPaymentPayload)) {
throw new ModelException("Payload not of type CreatePendingPaymentPayload", 500, []);
}
$data = $payload->serialize();
$version = $this->main()->GetEndpointVersion('REQUEST_ORDER');
$url = $this->api_url . $this->main()->GetEndpoint('REQUEST_ORDER');
$url = str_replace('v2', $version, $url);
$endpoint = '/' . $version . $this->main()->GetEndpoint('REQUEST_ORDER');
$options = $this->HmacCallOpts('POST', $endpoint, 'application/json;charset=UTF-8;', $data);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}
$options['TIMEOUT'] = 30;
/** @phpstan-ignore-next-line */
return $this->doCall('post',$url,$data,$options);
}

/**
* Fetches Payment details
*
* @param String $merchantPaymentId The unique payment transaction id provided by merchant
* @param String $paymentType Type of payment e.g. pending, continuous, direct_debit,web_cashier,dynamic_qr,app_invoke
* @return mixed
*/
public function getPaymentDetails($merchantPaymentId)
public function getPaymentDetails($merchantPaymentId, $paymentType = 'web_cashier')
{
$main = $this->MainInst;
$endpoint = '/v2' . $main->GetEndpoint('PAYMENT') . "/$merchantPaymentId";
$url = $this->api_url . $main->GetEndpoint('PAYMENT') . "/$merchantPaymentId";
$endpoint = $this->endpointByPaymentType($paymentType, $merchantPaymentId)['endpoint'];
$url = $this->endpointByPaymentType($paymentType, $merchantPaymentId)['url'];

$options = $this->HmacCallOpts('GET', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
Expand All @@ -105,12 +132,14 @@ public function getPaymentDetails($merchantPaymentId)
* Note: The Cancel API can be used until 00:14:59 AM the day after the Payment has happened.
* For 00:15 AM or later, please call the refund method to refund the payment.
* @param String $merchantPaymentId The unique payment transaction id provided by merchant
* @param String $paymentType Type of payment e.g. pending, continuous, direct_debit,web_cashier,dynamic_qr,app_invoke
* @return mixed
*/
public function cancelPayment($merchantPaymentId)
public function cancelPayment($merchantPaymentId, $paymentType = 'web_cashier')
{
$endpoint = '/v2' . $this->main()->GetEndpoint('PAYMENT') . "/$merchantPaymentId";
$url = $this->api_url . $this->main()->GetEndpoint('PAYMENT') . "/$merchantPaymentId";

$endpoint = $this->endpointByPaymentType($paymentType, $merchantPaymentId)['endpoint'];
$url = $this->endpointByPaymentType($paymentType, $merchantPaymentId)['url'];
$options = $this->HmacCallOpts('DELETE', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
Expand Down Expand Up @@ -215,4 +244,31 @@ private function doSimilarTransactionCall($url,$options,$data){
);
return json_decode($response->getBody(), true);
}
// Class helper
/**
* Returns endpoint data by payment type for payment details and cancellation
*
* @param String $paymentType Type of payment e.g. pending, continuous, direct_debit,web_cashier,dynamic_qr,app_invoke
* @param String $merchantPaymentId The merchant payment id for transaction
* @return array
*/
private function endpointByPaymentType($paymentType, $merchantPaymentId)
{
$main = $this->main();
switch ($paymentType) {
case 'pending':
$version = $this->main()->GetEndpointVersion('REQUEST_ORDER');
$endpoint = "/${version}" . $main->GetEndpoint('REQUEST_ORDER') . "/$merchantPaymentId";
$url = $this->api_url . $main->GetEndpoint('REQUEST_ORDER') . "/$merchantPaymentId";
$url = str_replace('v2', $version, $url);
break;

default:
$endpoint = '/v2' . $main->GetEndpoint('PAYMENT') . "/$merchantPaymentId";
$url = $this->api_url . $main->GetEndpoint('PAYMENT') . "/$merchantPaymentId";
break;
}
$endpointData = ["endpoint" => $endpoint, "url" => $url];
return $endpointData;
}
}
19 changes: 16 additions & 3 deletions src/Controllers/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,31 @@ public function __construct($MainInstance, $auth)
* Refund a payment
*
* @param RefundPaymentPayload $payload SDK payload object
* @param String $paymentType Type of payment e.g. pending, continuous, direct_debit,web_cashier,dynamic_qr,app_invoke
* @return mixed
*/
public function refundPayment($payload)
public function refundPayment($payload, $paymentType = 'web_cashier')
{
if (!($payload instanceof RefundPaymentPayload)) {
throw new ClientControllerException("Payload not of type RefundPaymentPayload", 1);
}
$main = $this->MainInst;
$url = $main->GetConfig('API_URL') . $main->GetEndpoint('REFUND');
$data = $payload->serialize();
$url = $main->GetConfig('API_URL') . $main->GetEndpoint('REFUND');
$endpoint = '/v2' . $main->GetEndpoint('REFUND');
switch ($paymentType) {
case 'pending':
$version = $this->main()->GetEndpointVersion('REQUEST_ORDER');
$endpoint = "/${version}" . $main->GetEndpoint('REQUEST_ORDER') . $main->GetEndpoint('REFUND');
$url = $this->api_url . $main->GetEndpoint('REQUEST_ORDER') . $main->GetEndpoint('REFUND');
$url = str_replace('v2', $version, $url);
break;

default:
$url = $main->GetConfig('API_URL') . $main->GetEndpoint('REFUND');
$endpoint = '/v2' . $main->GetEndpoint('REFUND');
break;
}

$options = $this->HmacCallOpts('POST', $endpoint, 'application/json;charset=UTF-8;', $data);
$mid = $this->main()->GetMid();
if ($mid) {
Expand Down
Loading

0 comments on commit b51f24a

Please sign in to comment.