Currency wont change after Init
See original GitHub issueHello! Im calling the initConfig after each change in the DOM, I do this because I’m deciding on which item that I want to buy, and depending on the Item you can get different currencies.
I am logging out this.paypalConfig and the currency is updating just fine, and the paypal button loads for a split second.
But when I click the button I instantly get an error saying: Error: Unexpected currency: SEK passed to order.create. Please ensure you are passing /sdk/js?currency=SEK in the paypal script tag.
If I understand correctly, then the paypalConfig.currency is the URL currency, which I earlier stated that it’s already SEK.
How does it come that the config / button doesn’t update with the latest value of the currency field?
The data that Im sending in:
{ "currency": "SEK", "clientId": "XXXXXX", "advanced": { "commit": "true" }, "style": { "label": "paypal", "layout": "vertical" } }
With the payload of:
[ { amount: { currency_code: 'SEK', value: '15', breakdown: { item_total: { currency_code: 'SEK', value: '15' } } }, items: [ { name: 'SAK NUMMER 2', quantity: '1', category: 'DIGITAL_GOODS', unit_amount: { currency_code: 'SEK', value: '15', }, } } ] } ]
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (5 by maintainers)
Top GitHub Comments
Yes, to some degree. I don’t have time to add new features, but will merge PRs and update to newer angular versions
Sure, even though i’m still testing it.
I have a form input for the amount, a select with the currencies and a component reference (<ng-container #paypal></ng-container>)
First thing I do is to initialize the button onInit(). so using the resolver function I pass to the component reference my paypal button component which will be in charge to show the button (using the configuration suggested by the owner of ngx-paypal) and get the feedback from paypal regarding the status of the transaction and eventually pass this status to the parent component.
Through the component reference instance properties (amount, currency, orderData and paypalClientId) I pass the data that are needed and I subscribe to the component reference instance to get the results emitted from the paypal button.
Every time the user change a currency I do this:
initPaypal(): void {
}
Basically, we need to remove every reference to the previous paypal button so it can be reinitialized. Until the user doesn’t input an import in the form the paypal button is disabled, when this change “onchange()” on the amount field I call again initPaypal() and the button will be enabled
I hope I have been clear with my explanation, it’s more difficult to explain that it actually is.