Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用自适应paypal API退还部分金额_Php_Paypal_Paypal Adaptive Payments_Chained Payments - Fatal编程技术网

Php 如何使用自适应paypal API退还部分金额

Php 如何使用自适应paypal API退还部分金额,php,paypal,paypal-adaptive-payments,chained-payments,Php,Paypal,Paypal Adaptive Payments,Chained Payments,我只是浏览了很多和这个话题相关的帖子,但并没有找到解决办法。我只想把我的部分货款退还给买家。比如,若买家支付了50美元的服务费,现在想要退款,那个么买家将获得2%的扣除额 下面的代码工作正常,全额退款,但我想要部分金额 这是我的密码: /* Refund API*/ $refundRequest = new RefundRequest(new RequestEnvelope("en_US")); //The receiver's email address, where n is between

我只是浏览了很多和这个话题相关的帖子,但并没有找到解决办法。我只想把我的部分货款退还给买家。比如,若买家支付了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);
}
/*退款API*/
$RETURNREQUEST=新的RETURNREQUEST(新请求信封(“en_US”));
//收件人的电子邮件地址,其中n在0和5之间,最多6个收件人
如果(isset($_POST['receiverEmail'])){
$receiver=array();
对于($i=0;$iemail=$_POST['receiverEmail'][$i];
$receiver[$i]->amount=$_POST['receiver amount'][$i];
$receiver[$i]->primary=$\u POST['primaryceiver'][$i];
如果($_POST['invoiceId'][$i]!=“”){
$receiver[$i]->invoiceId=$\u POST['invoiceId'][$i];
}
如果($\u POST['paymentType'][$i]!=“”&&&$\u POST['paymentType'][$i]!=默认值\u选择){
$receiver[$i]->paymentType=$\u POST['paymentType'][$i];
}
如果($\u POST['paymentSubType'][$i]!=“”){
$receiver[$i]->paymentSubType=$\u POST['paymentSubType'][$i];
}
如果($\u POST['phoneCountry'][$i]!=“”&&&$\u POST['phoneNumber'][$i]){
$receiver[$i]->phone=新电话号码类型($\u POST['phoneCountry'][$i],$\u POST['phoneNumber'][$i]);
如果($\u POST['phoneExtn'][$i]!=“”){
$receiver[$i]->phone->extension=$\u POST['phoneExtn'][$i];
}
}
}
$receiverList=新的receiverList($receiver);
}
如果($_POST['currencyCode']!=“”){
$RETURNEQUEST->currencyCode=$\u POST[“currencyCode”];
}
如果($_POST['payKey']!=“”){
$RETURNREQUEST->payKey=$\u POST[“payKey”];
}
如果($\u POST['transactionId']!=“”){
$RETURNRequest->transactionId=$\u POST[“transactionId”];
}
如果($\u POST['trackingId']!=“”){
$RETURNREQUEST->trackingId=$\u POST[“trackingId”];
}
//创建服务包装器对象
$service=new AdaptivePaymentsService(配置::getAcctAndConfig());
试一试{
/*使用try-catch包装服务对象上的API方法调用*/
$response=$service->return($returnrequest);
}捕获(例外$ex){
需要_once“Common/Error.php”;
出口
}
$ack=strtoupper($response->responseenevelope->ack);
如果($ack!=“成功”){
回显“错误:”;
}否则{
$status=$response->refundInfo列表->refundInfo[0]->refundStatus;
打印(回复);
}
有人能告诉我这个代码出了什么问题吗


谢谢

好的,我自己刚得到一个解决方案:

以下是经过编辑的代码,只需在请求中添加一个接收器阵列:

$refundRequest->receiverList = $receiverList;
你就完了

希望这能帮助别人