【问题标题】:Is Angular library "ngx-paypal" supports recurring payment?Angular 库“ngx-paypal”是否支持定期付款?
【发布时间】:2021-01-22 18:12:33
【问题描述】:

我想为我的 Angular 项目之一使用 paypal 库 ngx-paypal,我知道 javascript 库集成,但我想使用 angular 库,即 https://www.npmjs.com/package/ngx-paypal

是否支持循环支付

我关注链接:https://www.c-sharpcorner.com/article/implement-paypal-with-recurring-payment-using-angular-8/

【问题讨论】:

    标签: angular paypal paypal-sandbox paypal-subscriptions


    【解决方案1】:

    绝对可以使用 ngx-paypal 实现定期付款。

    plan-list.component.ts

    import { Component, OnInit, ViewChild } from "@angular/core";
    import {
      PayPalScriptService,
      IPayPalConfig,
      NgxPaypalComponent,
    } from "ngx-paypal";
    import { environment } from "../../environments/environment";
    import { plans } from "../plans";
    
    @Component({
      selector: "app-plan-list",
      templateUrl: "./plan-list.component.html",
      styleUrls: ["./plan-list.component.css"],
    })
    export class PlanListComponent implements OnInit {
      private plans = [];
      public configs = {};
    
      @ViewChild("basic") basicSubscription?: NgxPaypalComponent;
      @ViewChild("advanced") advancedSubscription?: NgxPaypalComponent;
    
      constructor(private payPalScriptService: PayPalScriptService) {
        this.plans = plans;
      }
    
      ngOnInit() {
        this.plans.map((plan) => {
          this.configs[plan.name] = this.getConfig(plan.id);
        });
        this.payPalScriptService.registerPayPalScript(
          {
            clientId: environment.paypalKey,
            currency: "USD",
            vault: "true",
          },
          (payPalApi) => {
            if (this.basicSubscription) {
              this.basicSubscription.customInit(payPalApi);
            }
            if (this.advancedSubscription) {
              this.advancedSubscription.customInit(payPalApi);
            }
          }
        );
      }
    
      getConfig(plan_id: string): IPayPalConfig {
        return {
          clientId: environment.paypalKey,
          currency: "USD",
          vault: "true",
          style: {
            label: "paypal",
            layout: "vertical",
            size: "small",
            shape: "pill",
            color: "silver",
            tagline: false,
          },
          createSubscription: function (data, actions) {
            return actions.subscription.create({
              plan_id,
            });
          },
          onApprove: function (data, actions) {
            console.log("subscription data:", data);
            actions.subscription.get().then((details) => {
              console.log("subscription details:", details);
              alert("Success to subscribe!");
            });
          },
          onCancel: (data, actions) => {
            console.log("OnCancel", data, actions);
          },
          onError: (err) => {
            console.log("OnError", err);
          },
          onClick: (data, actions) => {
            console.log("Clicked:", data, actions);
          },
        };
      }
    }
    
    

    plan-list.component.html

    <ngx-paypal
      #basic
      [config]="configs['basic']"
      [registerScript]="false"
    ></ngx-paypal>
    <ngx-paypal
      #advanced
      [config]="configs['advanced']"
      [registerScript]="false"
    ></ngx-paypal>
    
    

    计划.ts

    export const plans = [
      {
        id: "P-2D5563872K1616013MA4EJJQ",
        name: "basic",
        price: 9,
      },
      {
        id: "P-51W76656242348941MA4FEXI",
        name: "advanced",
        price: 99,
      },
    ];
    
    

    你可以找到完整的源代码here 您可以查看现场演示here

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 能分享一下这个功能的使用方法吗?我不知道如何将它与 ngx-paypal 一起使用
      • @rp07 你明白了吗?我发现他们支持它,但不幸的是他们没有关于如何使用它的文档。
      • 您是否已成功实施订阅功能,能否分享您的代码?
      猜你喜欢
      • 2013-05-25
      • 1970-01-01
      • 2010-12-27
      • 2017-06-03
      • 2013-07-10
      • 2020-07-29
      • 2013-04-25
      • 1970-01-01
      • 2020-01-03
      相关资源
      最近更新 更多