问题可能是由于使用Angular生产环境时未正确加载Paypal SDK库文件导致的。为确保正确加载Paypal SDK库文件并在Angular生产环境中显示Paypal按钮,请按照以下步骤操作:
npm install @paypal/checkout-sdk --save
import { PayPalScriptService, PayPalScriptLoaderOptions } from '@paypal/angular-components/paypal-script.service';
import { PAYPAL_SCRIPT_URL, PAYPAL_CLIENT_ID } from './app.config'; // Replace with your own PayPal configuration
const payPalScriptOptions: PayPalScriptLoaderOptions = {
'client-id': PAYPAL_CLIENT_ID,
'currency': 'USD'
};
@NgModule({
imports: [
PayPalButtonModule.forRoot(payPalScriptOptions)
]
})
export class AppModule {
constructor(scriptsLoader: PayPalScriptService) {
scriptsLoader.loadPayPalScript({ url: PAYPAL_SCRIPT_URL });
}
}
import { PayPalScriptService } from '@paypal/angular-components/paypal-script.service';
import { PAYPAL_CLIENT_ID } from './app.config'; // Replace with your own PayPal configuration
constructor(private paypalScriptService: PayPalScriptService) {}
this.paypalScriptService.loadPayPalScript().subscribe(() => {
// Render the PayPal button
paypal.Buttons({
createOrder: (data, actions) => {
// Set up the transaction
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
onApprove: (data, actions) => {
// Capture the funds from the transaction
下一篇:Angular生成的文件名太长