如何使用自适应贝宝 API 退还部分金额

Posted

技术标签:

【中文标题】如何使用自适应贝宝 API 退还部分金额【英文标题】:How to refund partial amount with adaptive paypal API 【发布时间】:2017-12-13 23:19:11 【问题描述】:

我刚刚浏览了很多与此主题相关的帖子,但找不到解决方案。我只想将我的部分金额退还给买家。就像如果买家支付了 50 美元的服务费,现在想要退款,那么买家将获得 2% 的折扣。

波纹管代码可以全额退款,但我想要部分退款。

这是我的代码:

/* Refund API*/
$refundRequest = new RefundRequest(new RequestEnvelope("en_US"));
//The receiver's email address, where n is between 0 and 5 for a maximum of 6 receivers
if(isset($_POST['receiverEmail'])) 
$receiver = array();
for($i=0; $i<count($_POST['receiverEmail']); $i++) 
    $receiver[$i] = new Receiver();
    $receiver[$i]->email = $_POST['receiverEmail'][$i];
    $receiver[$i]->amount = $_POST['receiverAmount'][$i];

    $receiver[$i]->primary = $_POST['primaryReceiver'][$i];
    if($_POST['invoiceId'][$i] != "") 
        $receiver[$i]->invoiceId = $_POST['invoiceId'][$i];
    
    if($_POST['paymentType'][$i] != "" && $_POST['paymentType'][$i] != DEFAULT_SELECT) 
        $receiver[$i]->paymentType = $_POST['paymentType'][$i];
    
    if($_POST['paymentSubType'][$i] != "") 
        $receiver[$i]->paymentSubType = $_POST['paymentSubType'][$i];
    
    if($_POST['phoneCountry'][$i] != "" && $_POST['phoneNumber'][$i]) 
        $receiver[$i]->phone = new PhoneNumberType($_POST['phoneCountry'][$i], $_POST['phoneNumber'][$i]);
        if($_POST['phoneExtn'][$i] != "") 
            $receiver[$i]->phone->extension = $_POST['phoneExtn'][$i];
        
    

   $receiverList = new ReceiverList($receiver);

if($_POST['currencyCode'] != "") 
   $refundRequest->currencyCode = $_POST["currencyCode"];


if($_POST['payKey'] != "") 
   $refundRequest->payKey = $_POST["payKey"];


if($_POST['transactionId'] != "") 
   $refundRequest->transactionId = $_POST["transactionId"];


if($_POST['trackingId'] != "") 
   $refundRequest->trackingId = $_POST["trackingId"];


//Creating service wrapper object
$service = new AdaptivePaymentsService(Configuration::getAcctAndConfig());
try 
  /* wrap API method calls on the service object with a try catch */
  $response = $service->Refund($refundRequest);
 catch(Exception $ex) 
   require_once 'Common/Error.php';
   exit;


$ack = strtoupper($response->responseEnvelope->ack);
if($ack != "SUCCESS")
   echo 'error:';
 else  
   $status = $response->refundInfoList->refundInfo[0]->refundStatus;
   print_r($response);

谁能告诉我这段代码有什么问题?

谢谢

【问题讨论】:

【参考方案1】:

好的,我自己找到了解决方案:

这里是编辑的代码,只是在请求中添加了一个接收器数组:

$refundRequest->receiverList = $receiverList;

你就完成了。

希望这会对某人有所帮助!

【讨论】:

以上是关于如何使用自适应贝宝 API 退还部分金额的主要内容,如果未能解决你的问题,请参考以下文章

当来电者和发件人相同时,如何使用贝宝自适应付款方式汇款?

通过贝宝付款完成后如何获取交易详情

贝宝自适应 API

订阅取消后 Stripe API 退款

贝宝集成 - 自适应支付 API

如何汇款到任何贝宝账户