如何修复“Object(...) 不是函数错误";在 Ionic 3 中使用 PayPal [英] How to fix "Object(...) is not a function error" using PayPal in Ionic 3

查看:15
本文介绍了如何修复“Object(...) 不是函数错误";在 Ionic 3 中使用 PayPal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我的 Ionic 应用程序,并且我在我的 Ionic 应用程序中使用了 PayPal.

I am working in my Ionic App and I have used the PayPal in my Ionic App.

这是我的 checkout.ts:

import { PayPal, PayPalPayment, PayPalConfiguration } from '@ionic-native/paypal/ngx';

constructor(private PayPalMobile: PayPal) { }

makepaymentp()
  {
    //console.log("Payment");
    this.PayPalMobile.init({
      PayPalEnvironmentProduction: 'YOUR_PRODUCTION_CLIENT_ID',
      PayPalEnvironmentSandbox: 'asasasasasasasasasas',
    }).then(() => {
      // Environments: PayPalEnvironmentNoNetwork, PayPalEnvironmentSandbox, PayPalEnvironmentProduction
      this.PayPalMobile.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({
        // Only needed if you get an "Internal Service Error" after PayPal login!
        //payPalShippingAddressOption: 2 // PayPalShippingAddressOptionPayPal
      })).then(() => {
        let payment = new PayPalPayment('3.33', 'INR', 'Description', 'sale');
        this.PayPalMobile.renderSinglePaymentUI(payment).then(() => {
          // Successfully paid

          // Example sandbox response
          //
          // {
          //   "client": {
          //     "environment": "sandbox",
          //     "product_name": "PayPal iOS SDK",
          //     "paypal_sdk_version": "2.16.0",
          //     "platform": "iOS"
          //   },
          //   "response_type": "payment",
          //   "response": {
          //     "id": "PAY-1AB23456CD789012EF34GHIJ",
          //     "state": "approved",
          //     "create_time": "2016-10-03T13:33:33Z",
          //     "intent": "sale"
          //   }
          // }
        }, () => {
          // Error or render dialog closed without being successful
        });
      }, () => {
        // Error in configuration
      });
    }, () => {
      // Error in initialization, maybe PayPal isn't supported or something else
    });

  }

这是我的 checkout.html:

<button class="myaddto22" [disabled]="!RadioValue" (click)="makepaymentp()" full ion-button round="true">
      Make Payment
</button>

这是我的 app.module.ts:

import { PayPal } from '@ionic-native/paypal/ngx';

providers: [PayPal]

我已经导入了运行 PayPal 所需的所有东西,但是当我运行 PayPal 代码时它显示错误.

I have imported all the things required to run the PayPal but when I am running the PayPal code it is showing the error.

Object(...) 不是 PayPal.init (index.js:28) 中的函数

Object(...) is not a function at PayPal.init (index.js:28)

非常感谢任何帮助.

推荐答案

由于你使用的是 Ionic v3,你应该 import PayPal from '@ionic-native/paypal' 不是来自 '@ionic-native/paypal/ngx'.

Since you are using Ionic v3 you should import PayPal from '@ionic-native/paypal' not from '@ionic-native/paypal/ngx'.

如果您使用 npm install @ionic-native/paypal 安装 PayPal 使用 npm uninstall @ionic-native/paypal 卸载它并重新- 使用 npm install --save @ionic-native/paypal@4

If you install PayPal using npm install @ionic-native/paypal uninstall it using npm uninstall @ionic-native/paypal and re-install using npm install --save @ionic-native/paypal@4

这篇关于如何修复“Object(...) 不是函数错误";在 Ionic 3 中使用 PayPal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆