如何解决"Object(...)不是函数错误"?在Ionic 3中使用PayPal [英] How to fix "Object(...) is not a function error" using PayPal in Ionic 3
问题描述
我正在使用Ionic应用程序,并且已经在我的Ionic应用程序中使用了PayPal.
这是我的 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.htm l:
<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代码时却显示错误.
Object(...)不是PayPal.init(index.js:28)上的函数
非常感谢您的帮助.
由于您使用的是Ionic v3,因此应import
PayPal
来自 '@ionic-native/paypal'
,而不是来自'@ionic-native/paypal/ngx'
. >
如果使用npm install @ionic-native/paypal
安装PayPal
,请使用npm uninstall @ionic-native/paypal
卸载,然后使用 npm install --save @ionic-native/paypal@4
I am working in my Ionic App and I have used the PayPal in my Ionic App.
This is my 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
});
}
This is my checkout.html:
<button class="myaddto22" [disabled]="!RadioValue" (click)="makepaymentp()" full ion-button round="true">
Make Payment
</button>
This is my app.module.ts:
import { PayPal } from '@ionic-native/paypal/ngx';
providers: [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(...) is not a function at PayPal.init (index.js:28)
Any help is much appreciated.
Since you are using Ionic v3 you should import
PayPal
from '@ionic-native/paypal'
not from '@ionic-native/paypal/ngx'
.
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屋!