django-oscar / django-oscar-paypal

PayPal integration for django-oscar. Can be used without Oscar too.
https://django-oscar-paypal.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
164 stars 215 forks source link

Replace U.S. State freeform text field with dropdown list #73

Closed natea closed 10 years ago

natea commented 10 years ago

I was using the sandbox site that ships with django-oscar-paypal, and when I clicked on the PayPal Express button on the payment details page, I was getting the message "An error occurred communicating with PayPal"

I looked in the log and saw this error (note: i've replaced the sensitive values with 'xxxxx')

DEBUG 2014-05-09 15:25:42,868 gateway 48455 4551610368 Making SetExpressCheckout request to https://api-3t.sandbox.paypal.com/nvp with params:
L_PAYMENTREQUEST_0_QTY0: 1
MAXAMT: 30.00
L_PAYMENTREQUEST_0_DESC0: test CD
REQCONFIRMSHIPPING: 0
SHIPTOCITY: Somerville
SHIPTONAME: Nate Aune
USER: smallslive+seller_api1.appsembler.com
SIGNATURE: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SHIPTOCOUNTRYCODE: US
EMAIL: nate@appsembler.com
SHIPTOZIP: 02144
ALLOWNOTE: 1
SHIPTOSTREET: 55 Franklin St. #2
CALLBACKTIMEOUT: 3
PAYMENTREQUEST_0_AMT: 30.00
PAYMENTREQUEST_0_HANDLINGAMT: 0.00
PAYMENTREQUEST_0_TAXAMT: 0.00
METHOD: SetExpressCheckout
PAYMENTREQUEST_0_ITEMAMT: 20.00
RETURNURL: http://localhost:8000/en-us/checkout/paypal/preview/1/
L_PAYMENTREQUEST_0_NAME0: Peter Bernstein
PAYMENTREQUEST_0_CURRENCYCODE: USD
VERSION: 88.0
PAYMENTREQUEST_0_MAXAMT: 30.00
L_PAYMENTREQUEST_0_AMT0: 20.00
SHIPTOSTREET2: 
L_PAYMENTREQUEST_0_NUMBER0: 1234567
SHIPTOSTATE: Massachusetts
PWD: xxxxxxxxxxxx
PAYMENTREQUEST_0_PAYMENTACTION: Sale
PAYMENTREQUEST_0_SHIPPINGAMT: 10.00
CANCELURL: http://localhost:8000/en-us/checkout/paypal/cancel/1/
ADDROVERRIDE: 1
DEBUG 2014-05-09 15:25:44,957 gateway 48455 4551610368 Response with params:
ACK: Failure
BUILD: 10952652
CORRELATIONID: 6e8c1e2c7d1d
L_ERRORCODE0: 10736
L_LONGMESSAGE0: A match of the Shipping Address City, State, and Postal Code failed.
L_SEVERITYCODE0: Error
L_SHORTMESSAGE0: Shipping Address Invalid City State Postal Code
TIMESTAMP: 2014-05-09T19:25:45Z
VERSION: 88.0
ERROR 2014-05-09 15:25:44,984 gateway 48455 4551610368 Error 10736 - A match of the Shipping Address City, State, and Postal Code failed.

Once I put in the form for the State field "MA" instead of "Massachusetts", then PayPal accepted the transaction and didn't report an error.

So I think it would be best to modify the payment details form to have a dropdown field instead of a freeform text field for the US State, to avoid this error if the user inadvertently types in the full state name, rather than the two letter abbreviation.

codeinthehole commented 10 years ago

This is a pesky shortcoming of the PayPal API. Since PayPal can be used in lots of countries other than the US, we can't use a US state dropdown by default. Individual projects can do this if they only ship to the US.

In https://github.com/tangentlabs/django-oscar-paypal/commit/849b577cd357adb583d9199052df1692417d30f9, I've added a snippet that attempts to use short versions of state names using the localflavor package. This handles the example here and should be an improvement overall.

natea commented 10 years ago

Could we have the U.S. State field appear conditionally if the user selects U.S. as the country? Or are you saying that the State field is used by other countries, to mean Province in Canada for example?

Thanks for adding the localflavor fix. I think that might be sufficient for now, but eventually we may want to replace it with a dropdown just to be extra safe.

codeinthehole commented 10 years ago

Could we have the U.S. State field appear conditionally if the user selects U.S. as the country? Or are you saying that the State field is used by other countries, to mean Province in Canada for example?

The state field is used by other countries, so you would need to use javascript to dynamically change the widget when the US country is selected. A bit fiddly.