question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Currency wont change after Init

See original GitHub issue

Hello! 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:closed
  • Created 4 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Enngagecommented, May 26, 2021

Yes, to some degree. I don’t have time to add new features, but will merge PRs and update to newer angular versions

0reactions
marshall86commented, Sep 22, 2021

Regarding to the currency change i found a way as well. I dynamically inject the ngx-paypal button in the page and every time i change currency i clear the button container, remove all the Paypal’s reference from the DOM and show again the button with a new config. If someone need it I can explain it better.

Hi! @marshall86 I met the same issue with changing currency. Could you please explain how have you implemented it?

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 {

if (this.form.valid) {

  this.submitAttempt = true;
  this.container.clear();

  // removing all reference to paypal
  const query = new RegExp('paypal|__zoid_|__post_robot_', 'i');
  Object.keys(window)
    .filter(k => query.test(k))
    .map(v => {
      delete window[v];
      return window[v];
    })
    .map((_v, i) => {
      if (i === 0) {
        return this.createPaypalComponent(false);
      }
    });

}

}

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to dynamically upda… | Apple Developer Forums
Is it possible to dynamically update the currency formatting of SwiftUI ... but if I change the currency after the View loads the...
Read more >
How do I change currency symbol on django-oscar dashboard?
No, it won't do that. Currency is completely separate from language, and has to be set explicitly by you in code.
Read more >
Critical Error after installing multi currency | WordPress.org
I can't find where to edit or change the multi currency back to single currency so I can get WooCommerce Payments works again....
Read more >
TextField Entry with .currency not working. Exact copy of Code ...
Hello, I am wondering why the code given is incorrect and won't run? import SwiftUI. struct ContentView: View {
Read more >
Changing currency in this Access template
You can follow the question or vote as helpful, but you cannot reply to this thread. I have the same question (86). Report...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found