Luehang / react-paypal-button-v2

An easy and simple to use React button component to implement PayPal Checkout with Smart Payment Buttons V2 (Version 2).
https://luehangs.site/lue_hang/projects/react-paypal-button-v2
MIT License
274 stars 81 forks source link

Error: Unexpected currency: JPY passed to order.create. Please ensure you are passing /sdk/js?currency=JPY in the paypal script tag. #4

Closed zhakamizhako closed 5 years ago

zhakamizhako commented 5 years ago

Hi, Good day. I've followed your examples, but i seem to stumble across an error whenever i try to change the currency. We're using React 15.6.2 with Redux 4.4.9.

Error: Unexpected currency: JPY passed to order.create. Please ensure you are passing /sdk/js?currency=JPY in the paypal script tag.

Here's my code for our page.

import { PayPalButton } from "react-paypal-button-v2";

import { toast } from 'react-toastify'

class PaymentTest extends Component {
  constructor (props) {
    super(props)

    this.state = {

    }
  }

  componentDidMount () {

  }

  componentWillReceiveProps (nextProps) {
    let { } = nextProps
  }

  render() {

    return (
      <PayPalButton
      amount="0.01"
      options={{currency:'JPY'}}

      onSuccess={(details, data) => {
        alert("Transaction completed by " + details.payer.name.given_name);

        // OPTIONAL: Call your server to save the transaction
        return fetch("/paypal-transaction-complete", {
          method: "post",
          body: JSON.stringify({
            orderID: data.orderID
          })
        });
      }}
    />
    );
  }
}

PaymentTest.propTypes = {

}

export default PaymentTest

Even then if i try to place it inside the <PayPalButton>, it returns with the same error.

<PayPalButton
      amount="0.01"
      currency='PHP'
      onSuccess={(details, data) => {
        alert("Transaction completed by " + details.payer.name.given_name);
        // OPTIONAL: Call your server to save the transaction
        return fetch("/paypal-transaction-complete", {
          method: "post",
          body: JSON.stringify({
            orderID: data.orderID
          })
        });
      }}
    /> 
Luehang commented 5 years ago

Hi,

Do you have a script tag anywhere in your html pointing to paypal's api or a tag that looks like this <script src="https://www.paypal.com/sdk/js?client-id=sb"></script>? If you do, then delete the script tag.

Luehang commented 5 years ago

If you like react-paypal-button-v2, please give it a star! Thanks.

Fl4v10 commented 5 years ago

Hi,

Do you have a script tag anywhere in your html pointing to paypal's api or a tag that looks like this <script src="https://www.paypal.com/sdk/js?client-id=sb"></script>? If you do, then delete the script tag.

Hello, thanks for the component and sorry for bad English.

I did not set the mentioned script but got the same error while passing different currencies.

At first, I've tried to pass the currency through the options and it doesn't work, then I passed by currency prop listed in IPayPalButtonProps and it worked for while until suddenly stop.

My code:

<PayPalButton
    amount={this.calcAmount()}
   currency={symbol}
   options={{
            clientId
   }}
   onSuccess={this.onSuccess.bind(this)}
   onError={this.onError.bind(this)}
/>

Error message: "Unexpected currency: EUR passed to order.create. Please ensure you are passing /sdk/js?currency=EUR in the paypal script tag."

Stack

Error: Unexpected currency: EUR passed to order.create. Please ensure you are passing /sdk/js?currency=EUR in the paypal script tag.
    at Xt.(anonymous function) (https://www.paypal.com/sdk/js?client-id=[CLIENT-ID]:1:51890)
    at Object.<anonymous> (https://www.paypal.com/sdk/js?client-id=[CLIENT-ID]:1:58149)
    at JSON.parse (<anonymous>)
    at o (https://www.paypal.com/sdk/js?client-id=[CLIENT-ID]:1:58009)
    at cr (https://www.paypal.com/sdk/js?client-id=[CLIENT-ID]:1:58160)
    at u.on (https://www.paypal.com/sdk/js?client-id=[CLIENT-ID]:1:62923)
    at gr (https://www.paypal.com/sdk/js?client-id=[CLIENT-ID]:1:63112)
    at https://www.paypal.com/sdk/js?client-id=[CLIENT-ID]0:1:67549
    at https://www.paypal.com/sdk/js?client-id=[CLIENT-ID]0:1:67595
svengau commented 4 years ago

In case someone has the same issue, you need to pass also the currency in the options:

         <PayPalButton
              amount={total}
              currency={currency}
              options={{
                currency: currency.toUpperCase(),
                clientId: PAYPAL_CLIENT_ID,
              }}
...