错误:使用 intent=capture 使用客户端捕获 [Paypal Javascript SDK]

问题描述

我正在使用 PayPal javascript SDK 为我的网页创建一个 Paypal 订阅按钮,问题在于使用沙盒帐户测试按钮时,在为订阅执行所有付款后,出现以下错误

Error: Use intent=capture to use client-side capture ...

这是我用来显示支付 PayPal 按钮的 HTML 脚本

 <script src="https://www.paypal.com/sdk/js?client-id=MY_CLIENT_ID&vault=true&intent=subscription&components=buttons"></script>
 <div id="paypal-button-container"></div>

这是我的 js 文件,它根据付款的操作和状态执行相应的处理程序:

paypal.Buttons({
    style: {
        shape: 'rect',color: 'black',layout: 'vertical',label: 'subscribe'
    },createSubscription: function(data,actions) {
      if (discordUser.value === "") {
        alert("Introduce tu usuario de discord");
        return;
      }

      slotDecremented = true;
      alterSlots();
      
      return actions.subscription.create({
        'plan_id': 'P-ID' // here is my plan id
      });
    },onApprove: function(data,actions) { 
      return actions.order.capture().then(function(details) {
        sendEmailToken(details.payer.email_address,discordUser.value,data.subscriptionID);
      });
    },onCancel: function(data) {
      alterSlots(true);
      slotDecremented = false;
    },onError: function(data) {
      if (!slotDecremented) {
        return;
      }

      alterSlots(true);
      slotDecremented = false;
    }
}).render('#paypal-button-container');

alterSlot() 函数使用 AJAX 对我的特定端点进行 API 调用,如果需要,只提供额外信息

编辑:

sendEmailToken() 函数向托管在我的服务器上的 API 发出 AJAX 请求,以便服务器执行正确的操作并确保安全(只是了解该部分发生情况的元数据)

解决方法

onApprove

asp-for 用于客户端一次性付款按钮。它不属于订阅按钮,因为没有要捕获的顺序。

参见例如PayPal 订阅文档,它的 <select name="Feature" id="Feature" asp-items="Html.GetEnumSelectList<Features.FeatureType>()"> <option selected="selected" value="">Please select</option> </select> 示例中只有一个基本的成功警报:https://developer.paypal.com/docs/subscriptions/integrate/#create-the-subscription


由于您的意图似乎是执行服务器端操作,例如在订阅批准后发送电子邮件,您应该从您的服务器激活所述订阅,以确保订阅不会在没有正确通知您的服务器的情况下变为活动状态这个事实。以下是一些信息:https://stackoverflow.com/a/65139331/2069605