Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't process subscription - angular 16: Uncaught Error: Must pass createSubscription with intent=subscription #242

Open
startupcode opened this issue Aug 17, 2023 · 9 comments

Comments

@startupcode
Copy link

Uncaught Error: Must pass createSubscription with intent=subscription

Hi can you please share how to use createSubscription. I'm using ngx-paypal 11.0.0 version and failed to implement subscription.

My code is like. tried every combination but not working. Please help need to make the website live.

this.payPalConfig = {
clientId: this.globalVar.PAYPAL_CLIENT_ID,
createSubscription: data => {
plan_id: _this.planID,
custom_id: _this.userdata.id,
intent: 'subscription'
},
intent: 'subscription',
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
vault: 'true',
advanced: {
intent: 'subscription', vault: 'true'
},
};
}

@saranglakare
Copy link

Has anyone found a solution for this? Is it working for you @startupcode ? Thanks

@saranglakare
Copy link

I found that ngx-paypal does not support createSubscription option at all. You can only create a subscription on client using createSubscriptionOnClient.

Example:

      createSubscriptionOnClient: (data) => <ICreateSubscriptionRequest>{
        plan_id: plan_id
      },

Where plan_id is a Subscription plan you have created with PayPal already.

@startupcode
Copy link
Author

Has anyone found a solution for this? Is it working for you @startupcode ? Thanks

Actually I found the other way round to implement this. My issue was when I was implementing intent Subscription and Capture both on same page.

So I have to implement this on separate page and made plan selection on other page. So based on plan selected I call subscription or capture functions.

Above code was correct and it worked.

To conclude, subscription and capture both not allowed on same page.

@saranglakare
Copy link

saranglakare commented Mar 6, 2024

Above code was correct and it worked.

Thanks for your reply @startupcode . Which version of the library are you using? With latest 11.0.0 the createSubscription option from user config does not work at all. I checked the code and it overrides it everytime, so the option seems useless. Only createSubscriptionOnClient works.

It'll be great if you can let me know if subscriptions are currently working for you with 11.0.0? Thanks!

@startupcode
Copy link
Author

Above code was correct and it worked.

Thanks for your reply @startupcode . Which version of the library are you using? With latest 11.0.0 the createSubscription option from user config does not work at all. I checked the code and it overrides it everytime, so the option seems useless. Only createSubscriptionOnClient works.

It'll be great if you can let me know if subscriptions are currently working for you with 11.0.0? Thanks!

Yes subscripotion working for me with above code using createSubscription. I'm using "ngx-paypal": "^11.0.0" library.

@saranglakare
Copy link

I'm using "ngx-paypal": "^11.0.0" library.

Thanks @startupcode . Which Angular version are you using?

When I check the code, intent: 'subscription' is not supported within createSubscription at all. So how come it is working? Can you re-check the exact code with what you have in the first post please?

@startupcode
Copy link
Author

startupcode commented Mar 7, 2024

I'm using "ngx-paypal": "^11.0.0" library.

Thanks @startupcode . Which Angular version are you using?

When I check the code, intent: 'subscription' is not supported within createSubscription at all. So how come it is working? Can you re-check the exact code with what you have in the first post please?

Hi, I'm using angular version:

Angular CLI: 16.1.6
Node: 16.20.1
Package Manager: npm 9.8.1
OS: darwin x64

Angular: 16.1.7
... animations, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.1601.6
@angular-devkit/build-angular 16.1.6
@angular-devkit/core 16.1.6
@angular-devkit/schematics 16.1.6
@angular/cli 16.1.6
@angular/fire 7.6.1
@schematics/angular 16.1.6
rxjs 7.8.1
typescript 4.9.5
zone.js 0.13.1


My Code is


import { ICreateSubscriptionRequest, IPayPalConfig, ICreateOrderRequest } from 'ngx-paypal';
public payPalConfig?: IPayPalConfig;

this.payPalConfig = {
clientId: PAYPAL_CLIENT_ID,
createSubscriptionOnClient: data => {
plan_id: _this.planID,
custom_id: _this.userdata.id,
},
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
vault: 'true',
advanced: {
extraQueryParams: [{ name: 'intent', value: 'subscription' }],
},
onApprove: (data, actions) => {
//console.log('onApprove - transaction is approved', data, actions);
},
onClientAuthorization: (data) => {
// console.log('onClientAuthorization - you should probably inform your server about completed transaction at this point', data);
},
onCancel: (data, actions) => {
// console.log('OnCancel', data, actions);
},
onError: err => {
console.log('OnError', err);
},
onClick: (data, actions) => {
// console.log('onClick', data, actions);
},
};

I have passed intent in advanced key.

Hope this helps.

@saranglakare
Copy link

Thanks .. you can see this code is very different from the original post. You are using createSubscriptionOnClient and not createSubscription which was the problem in your original code. There is no support for createSubscription any more. I am sending a PR to @Enngage soon with a fix. Right now there's no way to create a subscription on server with ngx-paypal.

@SiStibbs
Copy link

I have tried using the above code for creating a subscription. The transaction is approved but in onClientAuthorization I get an error because actions.order is undefined, and the library tries to read actions.order.capture().

Does anyone know how to fix this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants