通过Paypal REST API使用Paypal支付,无法在Paypal沙盒或生产环境中显示付款说明。

28
我正在实施Paypal的新REST API Pay with Paypal方法,可以在此处查看: https://developer.paypal.com/webapps/developer/docs/integration/web/accept-paypal-payment/ 支付执行得非常好,正如它应该的那样。用户选择使用Paypal支付,然后被重定向到Paypal网站,在那里他需要登录并批准付款。我向Paypal发送的JSON数据基本上与上面链接中指定的相同,我的数据看起来像这样:
{
  "intent":"sale",
  "redirect_urls":{
    "return_url":"http://<return URL here>",
    "cancel_url":"http://<cancel URL here>"
  },
  "payer":{
    "payment_method":"paypal"
  },
  "transactions":[
    {
      "amount":{
        "total":"7.47",
        "currency":"USD"
      },
      "description":"This is the payment description."
    }
  ]

由于它会将用户重定向到Paypal网站,因此描述和总金额列显示为空白

我不确定这是否是Paypal的REST API出现了错误,但我相信我已经提供了必要的付款描述+金额以便在此页面上反映。如果没有显示此信息,通常会对用户构成威慑,因为即使这笔金额在我的网站上列出,他们肯定也想在Paypal网站上看到他们支付的金额。

它看起来就像这样:

enter image description here

对于那些想指示用户尚未登录的人,即使在登录后,描述和当前购买栏仍然为空白。

是否有任何需要发送到Paypal以指示此描述数据的参数?

注意:此问题适用于生产和沙箱服务器。

2个回答

39
上面页面左侧的窗格显示: 1. 订单中的商品详情。在支付资源的交易详情中,您可以将商品列表包括在内。同样会在此处显示。 2. 交易金额的组成部分,例如运费、税费等——如果您在请求中包含它们。
尝试发送此请求以查看示例:
{
    "intent": "sale",
    "payer": {
        "payment_method": "paypal"
    },
    "redirect_urls": {
        "return_url": "http://<return url>",
        "cancel_url": "http://<cancle url>"
    },
    "transactions": [
        {
            "amount": {
                "total": "8.00",
                "currency": "USD",
                "details": {
                    "subtotal": "6.00",
                    "tax": "1.00",
                    "shipping": "1.00"
                }
            },
            "description": "This is payment description.",
            "item_list": { 
                "items":[
                    {
                        "quantity":"3", 
                        "name":"Hat", 
                        "price":"2.00",  
                        "sku":"product12345", 
                        "currency":"USD"
                    }
                ]
            }
        }
    ]
}

1
谢谢。Paypal rest api仍处于beta版本,需要进行严格的文档重写。顺便说一下,谢谢。 - Murtaza Khursheed Hussain
嗨Deepesh,我正在使用版本为1.4.3的PayPal。但我没有任何发送项目详情的方法。请帮助我。 - Madhu
2
将该精确示例粘贴到REST API playground中并添加有效的重定向URL会创建一个有效的请求,但是当您跟随批准URL时,侧边栏不会显示付款说明。 - Gerry Shaw
1
到了2015年中期,使用PayPal文档(REST API)仍然是一个猜测游戏。选项太多,排序不当,描述也不清楚。 - Arnaud Leyder
2015年即将结束,我花了一个小时试图弄清楚为什么用户被重定向到一个空的PayPal结帐页面。谢谢,这个答案解决了问题! :) - MrD
显示剩余6条评论

-1

谢谢。Madhu记得使用rest-api库!

Details amountDetails = new Details();
                    amountDetails.setSubtotal(autoregistro.getPedido().getItems().get(0).getTotal().toPlainString());
                    amountDetails.setTax("0");
                    amountDetails.setShipping("0");

                    Amount amount = new Amount();
                    amount.setCurrency("USD");
                    amount.setTotal(autoregistro.getPedido().getItems().get(0).getTotal().toPlainString());
                    // amount.setTotal("7.47"); // Los decimales deben ser con punto
                    amount.setDetails(amountDetails);

                    Item item = new Item();
                    item.setCurrency("USD");
                    item.setQuantity("1");
                    item.setName(autoregistro.getPedido().getItems().get(0).getDescripcion());
                    item.setPrice(amountDetails.getSubtotal());

                    List<Item> items = new ArrayList<Item>();
                    items.add(item);

                    ItemList itemList = new ItemList();
                    itemList.setItems(items);

                    Transaction transaction = new Transaction();
                    transaction.setDescription(item.getName());
                    transaction.setAmount(amount);
                    transaction.setItemList(itemList);

                    List<Transaction> transactions = new ArrayList<Transaction>();
                    transactions.add(transaction);

                    Payer payer = new Payer();
                    payer.setPaymentMethod("paypal");
                    // payer.setPaymentMethod("credit_card");

                    Payment payment = new Payment();
                    payment.setIntent("sale");
                    payment.setPayer(payer);
                    payment.setTransactions(transactions);
                    RedirectUrls redirectUrls = new RedirectUrls();
                    redirectUrls.setCancelUrl(this.configParameters.getAutoregistroURL() + "/pay_paypal?cancel=true");
                    redirectUrls.setReturnUrl(this.configParameters.getAutoregistroURL() + "/pay_paypal?success=true");
                    payment.setRedirectUrls(redirectUrls);

                    Payment createdPayment = payment.create(apiContext);

6
请提供更好的说明与您的代码一起使用。 - bwegs

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接