首页 > 解决方案 > 贝宝服务器 API。没有转账

问题描述

我正在将贝宝整合到我们的购物系统中。

我正在使用 Java API。

在当前形式中,过程如下:

  1. 用户选择paypal作为支付方式,点击“Pay Order”

  2. 服务器发送一个带有捕获意图的 createOrder 请求。

  3. 服务器收到带有链接的响应。

  4. 用户被重定向到“批准”链接。

  5. 完成后,贝宝将用户重定向到带有“感谢您的订单消息”的商店页面。

所有这些都按预期工作。

但是没有付款/没有转账。

我在这里做错了什么?

提前致谢!

供参考的请求/响应:

Request: {}, {
             "application_context" : {
                 "user_action" : "PAY_NOW",
                     "landing_page" : "BILLING",
                     "return_url" : "https://www.foobar.de.localhost:8443/payment/paypal?result=ok&order_id=MGS063464&secret=2E1C1B304178...",
                     "brand_name" : "<removed>",
                     "cancel_url" : "https://www.foobar.de.localhost:8443/payment/paypal?result=cancel&order_id=MGS063464",
                     "shipping_preference" : "SET_PROVIDED_ADDRESS"
             },
                 "purchase_units" : [ {
                     "amount" : {
                         "breakdown" : {
                             "shipping" : {
                                 "value" : "3",
                                 "currency_code" : "EUR"
                             },
                             "item_total" : {
                                 "value" : "2.45",
                                 "currency_code" : "EUR"
                             }
                         },
                         "value" : "5.45",
                         "currency_code" : "EUR"
                     },
                     "reference_id" : "MGS063464",
                     "shipping" : {
                         "address" : {
                             "country_code" : "DE",
                             "address_line_1" : "<removed>",
                             "admin_area_2" : "<removed>",
                             "postal_code" : "<removed>"
                         },
                         "name" : {
                             "full_name" : "<removed>"
                         }
                     },
                     "description" : "<removed>,
                     "items" : [ {
                         "quantity" : "1",
                         "name" : "<removed>",
                         "unit_amount" : {
                             "value" : "2.45",
                             "currency_code" : "EUR"
                         },
                         "sku" : "OCI08"
                     } ]
                 } ],
                 "intent" : "CAPTURE"
         }
Response: {}, {
              "create_time" : "2021-03-14T10:52:46Z",
                  "purchase_units" : [ {
                      "payee" : {
                          "email_address" : "<removed>",
                          "merchant_id" : "L4EC8HB5DTVSC"
                      },
                      "amount" : {
                          "breakdown" : {
                              "shipping" : {
                                  "value" : "3.00",
                                  "currency_code" : "EUR"
                              },
                              "item_total" : {
                                  "value" : "2.45",
                                  "currency_code" : "EUR"
                              }
                          },
                          "value" : "5.45",
                          "currency_code" : "EUR"
                      },
                      "reference_id" : "MGS063464",
                      "shipping" : {
                          "address" : {
                              "country_code" : "DE",
                              "address_line_1" : "<removed>",
                              "admin_area_2" : "<removed>",
                              "postal_code" : "<removed>"
                          },
                          "name" : {
                              "full_name" : "<removed>"
                          }
                      },
                      "description" : "<removed>",
                      "items" : [ {
                          "quantity" : "1",
                          "name" : "<removed>",
                          "unit_amount" : {
                              "value" : "2.45",
                              "currency_code" : "EUR"
                          },
                          "sku" : "OCI08"
                      } ]
                  } ],
                  "links" : [ {
                      "method" : "GET",
                      "rel" : "self",
                      "href" : "https://api.sandbox.paypal.com/v2/checkout/orders/5MY66978KX626104P"
                  }, {
                      "method" : "GET",
                      "rel" : "approve",
                      "href" : "https://www.sandbox.paypal.com/checkoutnow?token=5MY66978KX626104P"
                  }, {
                      "method" : "PATCH",
                      "rel" : "update",
                      "href" : "https://api.sandbox.paypal.com/v2/checkout/orders/5MY66978KX626104P"
                  }, {
                      "method" : "POST",
                      "rel" : "capture",
                      "href" : "https://api.sandbox.paypal.com/v2/checkout/orders/5MY66978KX626104P/capture"
                  } ],
                  "id" : "5MY66978KX626104P",
                  "intent" : "CAPTURE",
                  "status" : "CREATED"
          }

标签: javajsonapipaypal

解决方案


您缺少 API 调用,第 5 步应该改为:服务器发送捕获订单请求。

您最后的第 6 步应该是仅在捕获成功时才感谢买家

请参阅文档中的“捕获顺序” 。


对于旧网站,重定向到“批准”链接是一种旧的集成方法。对于现代用户体验,您应该通过将“创建订单”和“捕获订单”更改为仅返回 JSON 数据(没有其他 HTML 或文本)的两个服务器路由来保持页面加载(而不是重定向)

将这些路由与以下批准流程配对:https ://developer.paypal.com/demo/checkout/#/pattern/server


推荐阅读