当我遵循Paypal插件中的示例时,如何个性化totalAmount?

时间:2019-05-29 01:40:00

标签: paypal angular6 ionic4

我遵循了Ionic Paypal插件示例中的步骤,并使用沙箱正确部署了该应用程序。在生产中运行价格时如何个性化价格?

HTML代码:

<div class="card" *ngIf="cart$ | async as cart">
    <p class="card-text" *ngIf="cart">You have {{ cart.totalItemsCount }} items in your shopping cart.</p>

    TOTAL:
    <div class="float-right">
        {{ cart.totalPrice | currency: 'PHP ' }}
    </div>

    <ion-card-content>
        <ion-button expand="full" color="success" (click)="payWithPaypal()">Pay with PayPal</ion-button>
    </ion-card-content>
</div>
----------

TS代码:

@Input('cart') cart: ShoppingCart;
cart$: Observable < ShoppingCart > ;
let paymentAmount: string = '500'

payWithPaypal() {
        // console.log("Pay ????");
        this.payPal.init({
                PayPalEnvironmentProduction: 'Production Key',
                PayPalEnvironmentSandbox: 'Sandbox Key'
            }).then(() => {
                    // Environments: PayPalEnvironmentNoNetwork, PayPalEnvironmentSandbox, PayPalEnvironmentProduction
                    this.payPal.prepareToRender('PayPalEnvironmentProduction', new PayPalConfiguration({
                            // Only needed if you get an "Internal Service Error" after PayPal login!
                            //payPalShippingAddressOption: 2 // PayPalShippingAddressOptionPayPal
                        })).then(() => {

this.cart.totalPrice.toString()中使用paymentAmount时,它仅返回初始化错误,也许不支持PayPal或其他方式

this.cart.totalPrice投入生产后如何使用this.paymentAmount的值?

        let payment = new PayPalPayment(this.paymentAmount, 'PHP', 'Description', 'sale');
        this.payPal.renderSinglePaymentUI(payment).then((res) => {
          console.log(res);
          // Successfully paid
        }, () => {
          // Error or render dialog closed without being successful
        });
      }, () => {
        // Error in configuration
      });
    }, () => {
      // Error in initialization, maybe PayPal isn't supported or something else
    });
  }

0 个答案:

没有答案