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

Getting status error 400 when payee address are from Japan #15

Open
fabrijp opened this issue Jul 17, 2020 · 2 comments
Open

Getting status error 400 when payee address are from Japan #15

fabrijp opened this issue Jul 17, 2020 · 2 comments

Comments

@fabrijp
Copy link

fabrijp commented Jul 17, 2020

Hello.
I'm able to execute a payment successfully in sandbox mode but got status error 400 when in live mode.

Here is the code when executing the payment for both modes:

 func completePurchase(paymentID: String, payerID: String, price: Double, on req: Request) throws -> Future<String> {

    let payments = try req.make(Payments.self)

    let executor = Payment.Executor(payer: payerID, amounts: [ DetailedAmount(currency: .usd, total: .init(price), details: nil) ])

    return payments.execute(payment: paymentID, with: executor).transform(to: paymentID)

}

Any thoughts ? Thank you

@fabrijp
Copy link
Author

fabrijp commented Jul 17, 2020

Going further, looks like the PayPal response JSON are different while in live mode.
Got this from the execute function:
The data couldn’t be read because it isn’t in the correct format.

@fabrijp
Copy link
Author

fabrijp commented Jul 18, 2020

I have found the problem. There is nothing to do with live or sandbox mode. The issue was in the shipping address in the transaction array in the returned PayPal response. In my case, I have used my PayPal account to make a real purchase and since I live in Japan the state of my address in PayPal is TOCHIGI but in your model Address.swift you are using the enum Province for the state property that has a case for TOCHIGI-KEN. This was causing the encode to fail and Swift was returning a 400 status error code. I have changed the state property to be a String instead of the Province enum and it solved the issue. I believe any transaction from Japan will fail because of this. The -KEN is correctly used but somehow PayPal is not using it.

@fabrijp fabrijp changed the title Getting status error 400 when in live mode Getting status error 400 when payee address are from Japan Jul 18, 2020
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

1 participant