我在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.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代码时却显示错误。
Object(...)不是PayPal.init的函数(index.js:28)
任何帮助深表感谢。
最佳答案
由于使用的是Ionic v3,因此应从import
而不是PayPal
从'@ionic-native/paypal'
'@ionic-native/paypal/ngx'
。
如果使用PayPal
安装npm install @ionic-native/paypal
,请使用npm uninstall @ionic-native/paypal
卸载它,然后使用npm install --save @ionic-native/paypal@4
重新安装。
关于ionic-framework - 如何在Ionic 3中使用PayPal修复“Object(…)不是函数错误”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54838971/