繁体   English   中英

使用Laravel的Paypal退款金额

[英]Paypal Refund amount using laravel

我已经使用laravel成功实现了PayPal。 我可以使用PayPal API付款。 现在,我想使用laravel从PayPal退款。 我不想从贝宝(PayPal)仪表板退款,但我想从我们的管理面板中完成退款,管理员用户可以在其中查看付款清单并链接以将该金额退还给客户。 付款成功后,我得到了PayPal的交易ID。 如果我使用该交易ID进行退款,那么我将无法成功进行此操作,并且如果我从列出所有交易的Paypal仪表板复制交易ID并获取该交易的详细信息,那么我就能使退款成功。 谁能告诉我如何获取交易编号,使用laravel可以退款。

我必须使用以下代码来获取实际的销售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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM