【问题标题】:PayPal PHP SDK - cancel invoice function does nothingPayPal PHP SDK - 取消发票功能什么都不做
【发布时间】:2015-04-03 20:13:32
【问题描述】:

我正在使用PHP的PayPal SDK,我正在尝试取消发票,返回结果为“true”,没有返回异常,但发票没有取消。请你告诉我我的代码是否有错误?

$Invoice = new Invoice();

try {
    $invoice = $Invoice->get($id_invoice, $apiContext);
    $notify = new CancelNotification();
    $notify->setSubject("Past due")
           ->setNote("Canceling invoice")
           ->setSendToMerchant(true)
           ->setSendToPayer(true);
    $result = $Invoice->cancel($notify, $apiContext);

} catch (Exception $ex) {
    $result = self::getException($ex);
}

return $result;

【问题讨论】:

    标签: php paypal sdk invoice


    【解决方案1】:

    首先得到一个像这样的发票对象:

    $invoice = Invoice::get($invoiceId, $apiContext);
    

    然后,您可以执行以下操作来取消它。

    // ### Cancel Notification Object
    // This would send a notification to both merchant as well
    // the payer about the cancellation. The information of
    // merchant and payer is retrieved from the invoice details
    $notify = new CancelNotification();
    $notify
        ->setSubject("Past due")
        ->setNote("Canceling invoice")
        ->setSendToMerchant(true)
        ->setSendToPayer(true);
    // ### Cancel Invoice
    // Cancel invoice object by calling the
    // static `cancel` method
    // on the Invoice class by passing a valid
    // notification object
    // (See bootstrap.php for more on `ApiContext`)
    $cancelStatus = $invoice->cancel($notify, $apiContext);
    

    另外,要测试代码,您可以随时运行samples,然后自己测试一下,只需单击一个按钮。

    我运行了sample to cancel 发票,然后使用提供的类似信息获取发票回复:

    "metadata": {
        "created_date": "2015-02-04 13:12:33 PST",
        "first_sent_date": "2015-02-04 13:12:34 PST",
        "last_sent_date": "2015-02-04 13:12:34 PST",
        "payer_view_url": "https://www.sandbox.paypal.com/cgi_bin/webscr?cmd=_pay-inv&viewtype=altview&id=INV2-6S46-MLLN-3FEA-VLZE"
    }
    

    打开网址显示发票已取消,如下所示:

    【讨论】:

    • 太棒了!!看看您是否可以将此评论标记为答案。它可能会帮助其他面临类似问题的开发人员。
    猜你喜欢
    • 1970-01-01
    • 2019-03-26
    • 2018-08-19
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 2017-02-10
    • 2018-12-17
    • 2020-01-16
    相关资源
    最近更新 更多