首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用laravel的Paypal退款金额

使用laravel的Paypal退款金额
EN

Stack Overflow用户
提问于 2019-01-16 14:58:45
回答 1查看 653关注 0票数 0

我已经成功地用laravel实现了PayPal。我能够使用PayPal API进行支付。现在我想使用laravel实现从PayPal的退款。我不想从PayPal仪表板退款,但我想从我们的管理面板中完成,在那里管理员用户可以看到付款列表和链接,以退款给客户。成功付款后,我从PayPal获得了交易id作为响应。如果我使用交易id来退款,那么我就不能成功退款,如果我从列出了所有交易paypal仪表板中复制交易id并获得该交易的详细信息,那么我就能够成功退款。谁能告诉我如何获得交易id,我可以使用laravel进行退款。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-16 20:19:39

我必须使用以下代码来获得实际销售id退款使用代码,而不是从paypal仪表板

代码语言:javascript
复制
$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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54211831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档