php - 如何使用自适应 Paypal API 退还部分金额

标签 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 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);
}

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

谢谢

最佳答案

好吧,我自己找到了一个解决方案:

这里是经过编辑的代码,只是在请求中添加了一个 receivers 数组:

$refundRequest->receiverList = $receiverList;

你就完成了。

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

关于php - 如何使用自适应 Paypal API 退还部分金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45008381/

相关文章:

PHP If 函数内变量

c# - Paypal 订阅按钮错误

node.js - 是否可以使用 authToken 而不是客户端 ID/密码来配置 Paypal 的 Node SDK?

ios - 如何为PayPal自适应(MPL)付款进行服务器验证

api - PayPal API 详细信息 - 我自己也很困惑

paypal - 网站的应用程序提交阶段

javascript - 在 WordPress 主题模板中排队 jQuery 插件

php - fatal error : Call to undefined function openssl_random_pseudo_bytes()

php - file_get_contents 是否使用缓存?

php - Paypal 经常性/订阅集成问题