簡體   English   中英

Paypal SDK 不抓錢

[英]Paypal SDK is not capturing money

這是我的 NODEJS 應用請求。 我將客戶重定向到approve_url ,他在其中寫下他的詳細信息。 當 PayPal 接受客戶詳細信息時,它將帳戶重定向回return_url

問題是,成功重定向后,客戶不會被收費,我在 PayPal 中看不到任何活動。 我究竟做錯了什么?

let pay_req = {
  'intent': 'CAPTURE',
  "application_context": {
    'return_url': `https://api.domain.com/orders/success`,
    'cancel_url': `https://api.domain.com/orders/cancel`,
    "brand_name": "Domain",
    "locale": "en-US",
    landing_page: "BILLING",
    "user_action": "PAY_NOW"
  },
  "items": [
    {
      "name": entity.item.name,
      "description": entity.item.description,
      "unit_amount": {
        "currency_code": "USD",
        "value": entity.item.price
      },

      "quantity": request_body.qty,
      "category": "PHYSICAL_GOODS"
    }
  ],
  shipping_type: "shipping",
  purchase_units: [{
    "amount": {
      "currency_code": "USD",
      'value': total,
      "breakdown": {
        "item_total": {
          "currency_code": "USD",
          "value": subtotal
        },
        "shipping": {
          "currency_code": "USD",
          "value": shipping
        }
      }
    }
  }]
};
request.requestBody(pay_req);
let payPalClient = client();
let order;
try {
  order = await payPalClient.execute(request);
} catch (err) {

  // 4. Handle any errors from the call
  console.error(err);
  return err;
}
await strapi.services.order.update(
  {
    id: entity.id
  },
  {
    paypal_token: order.result.id
  }
);
var links = {};
order.result.links.forEach(function (linkObj) {
  links[linkObj.rel] = {
    'href': linkObj.href,
    'method': linkObj.method
  };
})
return links["approve"].href;

捕獲不是自動的。 您應該顯示一個訂單審查頁面,並在用戶確認訂單時發送捕獲請求。 如果您希望跳過訂單審核步驟並立即捕獲,您可以這樣做——但在這種情況下,您需要發送一個付款設置參數,將 PayPal 中的藍色“繼續”按鈕更改為“立即付款”(這只是外觀上的更改,但它會告知用戶將會發生什么)——盡管您進行了外觀上的更改,但您仍然必須在用戶返回 return_url 時立即發送捕獲請求。


為了獲得最佳結果:忘記所有這些,忘記使用重定向。 不要使用任何重定向。 完全沒有。 相反,切換到這個前端: https://developer.paypal.com/demo/checkout/#/pattern/server

這是一種更好的支付體驗,更符合現代 web 設計實踐,它使您的網站保持在后台加載並打開“上下文”批准 window。

(您可以通過單擊無服務器 HTML/JS-only版本查看有效的 UI 演示)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM