简体   繁体   English

没有按钮的 paypal 订阅方法 - Javascript/Angular

[英]paypal subscription method without the buttons - Javascript/Angular

I am making a payment checkout where i am implementing paypal.我正在付款结账,我正在实施 paypal。 I rendered the paypal buttons using their methods, but i want to place the actions of those buttons on my custom button and it not working.我使用他们的方法渲染了 paypal 按钮,但我想将这些按钮的操作放在我的自定义按钮上并且它不起作用。

I tried to change the function but it didnt work.我试图改变 function 但它没有用。

Here is the function to render the buttons and do the checkout action:这是 function 呈现按钮并执行结帐操作:

paypal.Buttons({
      style: {
        shape: 'rect',
        color: 'gold',
        layout: 'vertical',
        label: 'subscribe'
      },
      createSubscription(data, actions) {
        return actions.subscription.create({
          /* Creates the subscription */
          plan_id: 'My ID hiden'
        });
      },
      onApprove(data, actions) {
        alert(data.subscriptionID); // You can add optional success message for the subscriber here
      }
    }).render(this.paypalElement2.nativeElement);

I tried to make this:我试图做到这一点:

checkout() {
   paypal.Buttons({
        createSubscription(data, actions) {
          return actions.subscription.create({
            /* Creates the subscription */
            plan_id: ''
          });
        },
        onApprove(data, actions) {
          alert(data.subscriptionID); // You can add optional success message for the subscriber here
        }
      });

}

But when i press the button nothing happens.但是当我按下按钮时没有任何反应。

Is there a way to makie this work?有没有办法制作这项工作?

i want to place the actions of those buttons on my custom button我想将这些按钮的操作放在我的自定义按钮上

This cannot be done with the PayPal JavaScript, paypal.Buttons(...)不能用 PayPal JavaScript, paypal.Buttons(...)

If you want to use your own button to directly start the checkout, you need to integrate only with the PayPal REST API (no JS SDK) and redirect to the approve href returned when you create a subscription via API. If you want to use your own button to directly start the checkout, you need to integrate only with the PayPal REST API (no JS SDK) and redirect to the approve href returned when you create a subscription via API. This is not recommended, since it obviously involves redirecting away from your site.不建议这样做,因为它显然涉及从您的网站重定向。 Using the PayPal JS buttons is superior since it keeps your site loaded in the background and opens a small window for the payment approval.使用 PayPal JS 按钮效果更好,因为它可以让您的网站在后台加载,并打开一个小的 window 用于付款批准。

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

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