使用 laravel 的 Paypal 退款金额
Paypal Refund amount using laravel
我已经使用 laravel 成功实施了 PayPal。我可以使用 PayPal API 进行付款。现在我想使用 laravel 从 PayPal 实现退款。我不想从 PayPal 仪表板退款,但我想从我们的管理面板完成,管理员用户可以在其中查看付款列表和 link 以将该金额退还给客户。付款成功后,我收到了 PayPal 的交易 ID。如果我使用该交易 ID 退款,那么我无法成功退款,如果我从列出所有交易的贝宝仪表板复制交易 ID 并获取该交易的详细信息,那么我能够成功退款。任何人都可以告诉我如何获得我可以使用 laravel.
进行退款的交易 ID
我必须使用下面的代码来获取实际销售 ID 以使用不是来自 paypal 仪表板的代码退款金额
$apiContext = new ApiContext(new OAuthTokenCredential(
"<CLIENT_ID>", "<CLIENT_SCRET_KEY>")
);
$payments = Payment::get($payment_id, $apiContext);
$payments->getTransactions();
$obj = $payments->toJSON();//I wanted to look into the object
$paypal_obj = json_decode($obj);//I wanted to look into the object
$transaction_id = $paypal_obj->transactions[0]->related_resources[0]->sale->id;
$this->getRefundPayment($transaction_id);
public function getRefundPayment($transaction_id){
$this->API_UserName = urlencode($this->API_Username);
$this->API_Password = urlencode($this->API_Password);
$this->API_Signature = urlencode($this->Signature);
$this->version = urlencode($this->version);
$transactionid = $transaction_id;
$DataInArray['currencyCode'] = 'INR';
$DataInArray['refundType'] = 'Full';
$DataInArray['transactionID'] = $transactionid;
$DataInArray['invoiceID'] = '';
$DataInArray['memo'] = 'This is refund of transaction id ='.$transactionid;
$DataInArray['amount'] = '';
if(trim(@$DataInArray['currencyCode'])=="")
return array("ERROR_MESSAGE"=>"Currency Code is Missing");
if(trim(@$DataInArray['refundType'])=="")
return array("ERROR_MESSAGE"=>"Refund Type is Missing");
if(trim(@$DataInArray['transactionID'])=="")
return array("ERROR_MESSAGE"=>"Transaction ID is Missing");
$Api_request = "&TRANSACTIONID={$DataInArray['transactionID']}&REFUNDTYPE={$DataInArray['refundType']}&CURRENCYCODE={$DataInArray['currencyCode']}";
if(trim(@$DataInArray['invoiceID'])!="")
$Api_request = "&INVOICEID={$DataInArray['invoiceID']}";
if(isset($DataInArray['memo']))
$Api_request .= "&NOTE={$DataInArray['memo']}";
if(strcasecmp($DataInArray['refundType'], 'Partial') == 0) {
if(!isset($DataInArray['amount'])) {
return array("ERROR_MESSAGE"=>"For Partial Refund - It is essential to mention Amount");
} else {
$Api_request = $Api_request."&AMT={$DataInArray['amount']}";
}
if(!isset($DataInArray['memo'])) {
return array("ERROR_MESSAGE"=>"For Partial Refund - It is essential to enter text for Memo");
}
}
$curl_var = curl_init();
curl_setopt($curl_var, CURLOPT_URL, $this->API_Endpoint);
curl_setopt($curl_var, CURLOPT_VERBOSE, 1);
curl_setopt($curl_var, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl_var, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl_var, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_var, CURLOPT_POST, 1);
$Api_request_final = "METHOD=RefundTransaction&VERSION={$this->version}&PWD={$this->API_Password}&USER={$this->API_UserName}&SIGNATURE={$this->API_Signature}$Api_request";
curl_setopt($curl_var, CURLOPT_POSTFIELDS, $Api_request_final);
// Get response from the server.
$curlResponse = curl_exec($curl_var);
if(!$curlResponse)
return array("ERROR_MESSAGE"=>"RefundTransaction failed".curl_error($curl_var)."(".curl_errno($curl_var).")");
// Extract the response details.
$httpResponseAr = explode("&", $curlResponse);
$aryResponse = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$aryResponse[$tmpAr[0]] = urldecode($tmpAr[1]);
}
}
if((0 == sizeof($aryResponse)) || !array_key_exists('ACK', $aryResponse))
return array("ERROR_MESSAGE"=>"Invalid HTTP Response for POST request ($reqStr) to {$this->API_Endpoint}");
// var_dump($aryResponse);
return $aryResponse;
}
我已经使用 laravel 成功实施了 PayPal。我可以使用 PayPal API 进行付款。现在我想使用 laravel 从 PayPal 实现退款。我不想从 PayPal 仪表板退款,但我想从我们的管理面板完成,管理员用户可以在其中查看付款列表和 link 以将该金额退还给客户。付款成功后,我收到了 PayPal 的交易 ID。如果我使用该交易 ID 退款,那么我无法成功退款,如果我从列出所有交易的贝宝仪表板复制交易 ID 并获取该交易的详细信息,那么我能够成功退款。任何人都可以告诉我如何获得我可以使用 laravel.
进行退款的交易 ID我必须使用下面的代码来获取实际销售 ID 以使用不是来自 paypal 仪表板的代码退款金额
$apiContext = new ApiContext(new OAuthTokenCredential(
"<CLIENT_ID>", "<CLIENT_SCRET_KEY>")
);
$payments = Payment::get($payment_id, $apiContext);
$payments->getTransactions();
$obj = $payments->toJSON();//I wanted to look into the object
$paypal_obj = json_decode($obj);//I wanted to look into the object
$transaction_id = $paypal_obj->transactions[0]->related_resources[0]->sale->id;
$this->getRefundPayment($transaction_id);
public function getRefundPayment($transaction_id){
$this->API_UserName = urlencode($this->API_Username);
$this->API_Password = urlencode($this->API_Password);
$this->API_Signature = urlencode($this->Signature);
$this->version = urlencode($this->version);
$transactionid = $transaction_id;
$DataInArray['currencyCode'] = 'INR';
$DataInArray['refundType'] = 'Full';
$DataInArray['transactionID'] = $transactionid;
$DataInArray['invoiceID'] = '';
$DataInArray['memo'] = 'This is refund of transaction id ='.$transactionid;
$DataInArray['amount'] = '';
if(trim(@$DataInArray['currencyCode'])=="")
return array("ERROR_MESSAGE"=>"Currency Code is Missing");
if(trim(@$DataInArray['refundType'])=="")
return array("ERROR_MESSAGE"=>"Refund Type is Missing");
if(trim(@$DataInArray['transactionID'])=="")
return array("ERROR_MESSAGE"=>"Transaction ID is Missing");
$Api_request = "&TRANSACTIONID={$DataInArray['transactionID']}&REFUNDTYPE={$DataInArray['refundType']}&CURRENCYCODE={$DataInArray['currencyCode']}";
if(trim(@$DataInArray['invoiceID'])!="")
$Api_request = "&INVOICEID={$DataInArray['invoiceID']}";
if(isset($DataInArray['memo']))
$Api_request .= "&NOTE={$DataInArray['memo']}";
if(strcasecmp($DataInArray['refundType'], 'Partial') == 0) {
if(!isset($DataInArray['amount'])) {
return array("ERROR_MESSAGE"=>"For Partial Refund - It is essential to mention Amount");
} else {
$Api_request = $Api_request."&AMT={$DataInArray['amount']}";
}
if(!isset($DataInArray['memo'])) {
return array("ERROR_MESSAGE"=>"For Partial Refund - It is essential to enter text for Memo");
}
}
$curl_var = curl_init();
curl_setopt($curl_var, CURLOPT_URL, $this->API_Endpoint);
curl_setopt($curl_var, CURLOPT_VERBOSE, 1);
curl_setopt($curl_var, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl_var, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl_var, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_var, CURLOPT_POST, 1);
$Api_request_final = "METHOD=RefundTransaction&VERSION={$this->version}&PWD={$this->API_Password}&USER={$this->API_UserName}&SIGNATURE={$this->API_Signature}$Api_request";
curl_setopt($curl_var, CURLOPT_POSTFIELDS, $Api_request_final);
// Get response from the server.
$curlResponse = curl_exec($curl_var);
if(!$curlResponse)
return array("ERROR_MESSAGE"=>"RefundTransaction failed".curl_error($curl_var)."(".curl_errno($curl_var).")");
// Extract the response details.
$httpResponseAr = explode("&", $curlResponse);
$aryResponse = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$aryResponse[$tmpAr[0]] = urldecode($tmpAr[1]);
}
}
if((0 == sizeof($aryResponse)) || !array_key_exists('ACK', $aryResponse))
return array("ERROR_MESSAGE"=>"Invalid HTTP Response for POST request ($reqStr) to {$this->API_Endpoint}");
// var_dump($aryResponse);
return $aryResponse;
}