Skip to content

Commit

Permalink
De-duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
paypay-ayas committed Sep 28, 2020
1 parent 152e79e commit 30d3936
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 74 deletions.
15 changes: 3 additions & 12 deletions src/Controllers/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ public function createQRCode($payload)
$data = $payload->serialize();
$endpoint = '/v2' . $this->main()->GetEndpoint('CODE');
$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;

if ($data) {
Expand All @@ -56,10 +53,7 @@ public function getPaymentDetails($merchantPaymentId)
$endpoint = '/v2' . $this->main()->GetEndpoint('CODE') . $main->GetEndpoint('PAYMENT') . "/$merchantPaymentId";
$url = $this->api_url . $main->GetEndpoint('CODE') . $main->GetEndpoint('PAYMENT') . "/$merchantPaymentId";
$options = $this->HmacCallOpts('GET', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}

return $this->doCall('get',$url,[],$options);
}

Expand All @@ -74,10 +68,7 @@ public function deleteQRCode($codeId)
{
$endpoint = '/v2' . $this->main()->GetEndpoint('CODE') . "/$codeId";
$options = $this->HmacCallOpts('DELETE', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}

$url = $this->api_url . $this->main()->GetEndpoint('CODE') . "/$codeId";
return $this->doCall('delete',$url,[],$options);
}
Expand Down
47 changes: 13 additions & 34 deletions src/Controllers/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ public function createPayment($payload, $agreeSimilarTransaction = false)
$url = $this->api_url . $this->main()->GetEndpoint('PAYMENT');
$endpoint = '/v2' . $this->main()->GetEndpoint('PAYMENT');
$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;
if ($agreeSimilarTransaction) {
return $this->doSimilarTransactionCall($url,$options,$data);
Expand All @@ -70,10 +67,7 @@ public function createContinuousPayment($payload)
$url = str_replace('v2', $version, $url);
$endpoint = '/' . $version . $this->main()->GetEndpoint('SUBSCRIPTION');
$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;
return $this->doCall('post',$url,$data,$options);

Expand All @@ -95,10 +89,7 @@ public function createPendingPayment($payload)
$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);
Expand All @@ -117,10 +108,7 @@ public function getPaymentDetails($merchantPaymentId, $paymentType = 'web_cashie
$url = $this->endpointByPaymentType($paymentType, $merchantPaymentId)['url'];

$options = $this->HmacCallOpts('GET', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}

return $this->doCall('get',$url,[],$options);
}

Expand All @@ -141,10 +129,7 @@ public function cancelPayment($merchantPaymentId, $paymentType = 'web_cashier')
$endpoint = $this->endpointByPaymentType($paymentType, $merchantPaymentId)['endpoint'];
$url = $this->endpointByPaymentType($paymentType, $merchantPaymentId)['url'];
$options = $this->HmacCallOpts('DELETE', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}


return $this->doCall('delete',$url,[],$options);
}
Expand All @@ -164,10 +149,7 @@ public function createPaymentAuth($payload, $agreeSimilarTransaction = false)
$url = $this->api_url . $this->main()->GetEndpoint('PAYMENT_PREAUTH');
$endpoint = '/v2' . $this->main()->GetEndpoint('PAYMENT_PREAUTH');
$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;
if ($agreeSimilarTransaction) {
return $this->doSimilarTransactionCall($url,$options,$data);
Expand All @@ -192,10 +174,7 @@ public function capturePaymentAuth($payload)
$url = $main->GetConfig('API_URL') . $main->GetEndpoint('PAYMENT') . "/capture";
$endpoint = '/v2' . $this->main()->GetEndpoint('PAYMENT') . "/capture";
$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;
return $this->doCall('post',$url,$data,$options);
}
Expand All @@ -217,10 +196,7 @@ public function revertAuth($payload)
$url = $main->GetConfig('API_URL') . $main->GetEndpoint('PAYMENT') . "/preauthorize/revert";
$endpoint = '/v2' . $this->main()->GetEndpoint('PAYMENT') . "/preauthorize/revert";
$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;
return $this->doCall('post',$url,$data,$options);
}
Expand All @@ -233,6 +209,10 @@ public function revertAuth($payload)
* @return array
*/
private function doSimilarTransactionCall($url,$options,$data){
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}
$response = $this->main()->http()->post(
$url,
[
Expand Down Expand Up @@ -268,7 +248,6 @@ private function endpointByPaymentType($paymentType, $merchantPaymentId)
$url = $this->api_url . $main->GetEndpoint('PAYMENT') . "/$merchantPaymentId";
break;
}
$endpointData = ["endpoint" => $endpoint, "url" => $url];
return $endpointData;
return ["endpoint" => $endpoint, "url" => $url];
}
}
10 changes: 2 additions & 8 deletions src/Controllers/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ public function refundPayment($payload, $paymentType = 'web_cashier')
}

$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;
return $this->doCall('post',$url,$data,$options);
}
Expand All @@ -67,10 +64,7 @@ public function getRefundDetails($merchantRefundId)
$url = $main->GetConfig('API_URL') . $main->GetEndpoint('REFUND') . "/$merchantRefundId";
$endpoint = '/v2' . $main->GetEndpoint('REFUND') . "/$merchantRefundId";
$options = $this->HmacCallOpts('GET', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}

return $this->doCall('get',$url,[],$options);
}
}
20 changes: 4 additions & 16 deletions src/Controllers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ public function unlinkUser($userAuthorizationId = false)
$url = $this->api_url . $this->main()->GetEndpoint('USER_AUTH') . "/$userAuthorizationId";
$endpoint = 'v2' . $this->main()->GetEndpoint('USER_AUTH') . "/$userAuthorizationId";
$options = $this->HmacCallOpts('DELETE', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}

return $this->doCall('delete',$url,[],$options);
}

Expand All @@ -66,10 +63,7 @@ public function createAccountLinkQrCode($payload)
$endpoint = '/v1' . $this->main()->GetEndpoint('SESSIONS');
$data = $payload->serialize();
$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'] = 10;
if ($data) {
Expand Down Expand Up @@ -102,10 +96,7 @@ public function getUserAuthorizationStatus($userAuthorizationId)
$url = $this->api_url . $this->main()->GetEndpoint('USER_AUTH');
$endpoint = '/v2' . $this->main()->GetEndpoint('USER_AUTH');
$options = $this->HmacCallOpts('GET', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}

return $this->doAuthCall($url,$options,$userAuthorizationId);
}

Expand All @@ -123,10 +114,7 @@ public function getMaskedUserProfile($userAuthorizationId)
$url = $this->api_url . $this->main()->GetEndpoint('USER_PROFILE_SECURE');
$endpoint = '/v2' . $this->main()->GetEndpoint('USER_PROFILE_SECURE');
$options = $this->HmacCallOpts('GET', $endpoint);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}

return $this->doAuthCall($url,$options,$userAuthorizationId);
}
/**
Expand Down
5 changes: 1 addition & 4 deletions src/Controllers/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public function checkWalletBalance($userAuthorizationId, $amount, $currency, $pr
$url = $this->api_url . $this->main()->GetEndpoint('WALLET_BALANCE');
$endpoint = '/v2' . $this->main()->GetEndpoint('WALLET_BALANCE');
$options = $this->HmacCallOpts('GET', $endpoint, 'application/json;charset=UTF-8;', $data);
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}

return $this->doCall('get',$url,[],$options);
}
}
4 changes: 4 additions & 0 deletions src/core/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ protected function payloadTypeCheck($payload,$type){
*/
protected function doCall($callType,$url,$data,$options){
$request=$this->main()->http();
$mid = $this->main()->GetMid();
if ($mid) {
$options["HEADERS"]['X-ASSUME-MERCHANT'] = $mid;
}
$response = null;
if ($callType == 'post') {
$response = $request->$callType(
Expand Down

0 comments on commit 30d3936

Please sign in to comment.