简体   繁体   English

使用Paypal Rest API退款给用户

[英]Refund users using paypal rest API

I'm developping a web application on which I allow the users to buy a ticket for an event. 我正在开发一个Web应用程序,允许用户购买事件门票。 I used the Paypal Rest API for sending money and purchasing the tickets.Everything is working just fine. 我使用Paypal Rest API进行汇款和购买门票,一切正常。 Now I'm trying to use the refund method to refund all users related to an event when this event will be cancelled. 现在,当事件被取消时,我正在尝试使用退款方法来退款与该事件相关的所有用户。 Looking in the REST API documentation I found that there is a way to refund but when I search in the REST API package for laravel I haven't found how to refund or use the refund method. 通过查看REST API文档,我发现可以退款,但是当我在REST API软件包中搜索laravel ,却没有找到如何退款或使用退款方法。 Does rest-api-sdk-php doesn't support the refund method? rest-api-sdk-php不支持退款方法吗? And if yes how to use it in laravel project? 如果是的话,如何在laravel项目中使用它? PS: the payment are done without a credit card.I use just the paypal acount with sandbox. 附言:付款无需信用卡即可完成。我只使用带有沙盒的Paypal帐户。 --edit-- I get this result when trying the refund code of the rest api: --edit--尝试使用其他api的退款代码时,我得到以下结果:

{"name":"TRANSACTION_REFUSED","message":"The request was refused.{0}","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#TRANSACTION_REFUSED","debug_id":"97f33dd89f4c8"}

I am not quite sure about laravel project, but the PHP SDK does have ability to refund. 我对laravel项目不太确定,但是PHP SDK确实可以退款。 Simply create a Refund object and pass it to refund method in Sale object. 只需创建一个退款对象并将其传递给销售对象中的退款方法即可。 Sample code from https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/sale/RefundSale.php : 来自https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/sale/RefundSale.php的示例代码:

// ### Refund object
$refund = new Refund();
$refund->setAmount($amt);
// ###Sale
// A sale transaction.
// Create a Sale object with the
// given sale transaction id.
$sale = new Sale();
$sale->setId($saleId);
try {
    // Create a new apiContext object so we send a new
    // PayPal-Request-Id (idempotency) header for this resource
    $apiContext = getApiContext($clientId, $clientSecret);
    // Refund the sale
    // (See bootstrap.php for more on `ApiContext`)
    $refundedSale = $sale->refund($refund, $apiContext);
} catch (Exception $ex) {
    ResultPrinter::printError("Refund Sale", "Sale", $refundedSale->getId(), $refund, $ex);
    exit(1);
}

The error you are getting (The request was refused.) 您收到的错误(请求被拒绝。)

Without seeing your code, any of the following could be the reason: 没有看到您的代码,可能是以下任何原因:

The partial refund amount must be less than or equal to the original transaction amount 部分退款金额必须小于或等于原始交易金额

The partial refund amount must be less than or equal to the remaining amount 部分退款金额必须小于或等于剩余金额

The partial refund amount is not valid 部分退款金额无效

The partial refund must be the same currency as the original transaction 部分退款必须与原始交易使用相同的币种

Because a complaint case exists on this transaction, only a refund of the full or full remaining amount of the transaction can be issued 由于此交易中存在投诉案件,因此只能退还该交易的全部或全部余额

You are over the time limit to perform a refund on this transaction 您已超过时间限制,无法对此笔交易退款

Cannot do a full refund after a partial refund 部分退款后无法全额退款

This transaction has already been fully refunded 此交易已全额退款

You cannot refund this type of transaction 您无法退还此类交易

You cannot do a partial refund on this transaction 您无法对此交易进行部分退款

The merchant account has limitations or restrictions 商家帐户有限制或限制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM