PayPal - Shipping method name is None

591 views
Skip to first unread message

Charles Quéinnec

unread,
Sep 4, 2013, 6:23:57 AM9/4/13
to django...@googlegroups.com
Hi,

When doing payments with PayPal, shipping method is always set to None, while I defined 3 methods in custom repository :

class Standard(core_methods.FixedPrice):
    code = 'standard'
    name = "Livraison Chronopost"

class Magasin(core_methods.Free):
    code = 'magasin'
    name = "Retrait en magasin"

class Livreur(core_methods.FixedPrice):
    code = 'livreur'
    name = "Livraison Express"

class Repository(repository.Repository):
    methods = [Standard(D('5.00')), Magasin(), Livreur(D('40.00'))]

    def get_shipping_methods(self, user, basket, shipping_addr=None, **kwargs):
        return self.prime_methods(basket, self.methods)

    def find_by_code(self, code, basket):
        for method in self.methods:
            if code == method.code:
                return self.prime_method(basket, method)


After some digging in the code of django-oscar-paypal, I figured out that the shipping method name is sent back from PayPal in parameter SHIPPINGOPTIONNAME.
It is used in two places in paypal / express / views.py, in class SuccessResponseView :
- in get_context_data :
line 227 :
ctx['shipping_method'] = {
'name': self.txn.value('SHIPPINGOPTIONNAME'),
'description': '',
'basket_charge_incl_tax': D(self.txn.value('SHIPPINGAMT')),
}
- in get_shipping_method :
line 300 :
method.name = self.txn.value('SHIPPINGOPTIONNAME')


However, self.txn doesn't have this value assigned, and returns None. I managed to retrieve the method name based on the price (from PAYMENTREQUEST_0_SHIPPINGAMT) but even if it works, this is a bit dirty.

Am I missing something in the way of retrieving shipping method name ? Is it normal that PayPal doesn't send back the SHIPPINGOPTIONNAME parameter ?

Bonus question : is it possible to override SuccessResponseView in my project directly, rather than modifying python lib paypal code ?

Thanks a lot for your help !
Regards,

- Charles

David Winterbottom

unread,
Sep 4, 2013, 3:09:54 PM9/4/13
to django-oscar
​No, I don't think it is.  I just tried an order in the sandbox site within the oscar-paypal repo and it worked ok.  From the basket page, I clicked through to PayPal, where I could choose a shipping method:

Inline images 1

When back in the sandbox site, the shipping method name was correctly retrieved:

Inline images 2

so I'm not sure what is causing your issue.  I presume you are going straight to PayPal from the basket page?  Also, check that your shipping methods are being correctly submitted to PayPal.


 

Bonus question : is it possible to override SuccessResponseView in my project directly, rather than modifying python lib paypal code ?

Hmm, perhaps not that easily.  The URL to the response view is hardcoded within the facade.  To use your own SuccessResponseView (which could be a subclass of the original, with customisations), you will need to ensure that your new view resolves under the URL name 'paypal-success-response'.  I'm not sure how easy that is.  One fairly drastic way would be to not include 'paypal.express.urls' in your urls.py but replace them with your own set that use the same URL names.  Then you could use a custom SuccessResponse view.

Can you create a github issue to change the package to make this easier?


 

Thanks a lot for your help !
Regards,

- Charles

--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-oscar/bac836c6-d2c2-4b16-9e93-df79bef536b9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
David Winterbottom
Head of Programming

Tangent Labs
84-86 Great Portland Street
London W1W 7NR
England, UK

image.png
image.png

Charles Quéinnec

unread,
Sep 5, 2013, 3:39:26 AM9/5/13
to django...@googlegroups.com
Hi,

Thanks for those precisions.

In my case, I'm validating basket with standard checkout process steps, through my oscar project :
1. select shipping address
2. select shipping method
3. select payment method, then redirect to paypal if selected as the payment method
4. and then back to order confirmation

If I check express transactions in the admin, I don't see any reference to shipping methods : fields which are sent in the request are :
Images intégrées 2

In the scenario of choosing the shipping method on the site, are there any modifications to apply, or things to customize, in order to have this method name sent to and returned from paypal ?
I can't find any reference to shipping method name in set_txn, for exemple.

Thanks again for your time and help.

- Charles


2013/9/4 David Winterbottom <david.win...@tangentlabs.co.uk>
You received this message because you are subscribed to a topic in the Google Groups "django-oscar" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-oscar/8_eGp_2WG-U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-oscar...@googlegroups.com.
image.png

David Winterbottom

unread,
Sep 5, 2013, 5:27:51 AM9/5/13
to django-oscar
Yes, I can recreate that issue.  It seems that there's no way to pass the shipping method name to PayPal when you are specifying the shipping amount explicitly.

I have found a workaround where, if there is no shipping name in the PayPal txn, we look at the original shipping method from the session:

Can you see if this updated version works for you?  If it does, I'll cut a new release to PyPI.



For more options, visit https://groups.google.com/groups/opt_out.
image.png

Charles Quéinnec

unread,
Sep 5, 2013, 4:24:38 PM9/5/13
to django...@googlegroups.com
Hi,

Little typo I think : in get_shipping_method, method.name is not assigned if name is not None :

name = self.txn.value('SHIPPINGOPTIONNAME')
if not name:
    # Look to see if there is a method in the session
    session_method = self.checkout_session.shipping_method(basket)
    if session_method:
          method.name = session_method.name
else:
    method.name = name



Otherwise it works great, I just did some tests and it's fine.
Thanks again for the time you spent on this !

- Charles


2013/9/5 David Winterbottom <david.win...@tangentlabs.co.uk>
image.png

David Winterbottom

unread,
Sep 6, 2013, 7:04:02 AM9/6/13
to django-oscar
On 5 September 2013 21:24, Charles Quéinnec <charles....@gmail.com> wrote:
Hi,

Little typo I think : in get_shipping_method, method.name is not assigned if name is not None :

name = self.txn.value('SHIPPINGOPTIONNAME')
if not name:
    # Look to see if there is a method in the session
    session_method = self.checkout_session.shipping_method(basket)
    if session_method:
          method.name = session_method.name
else:
    method.name = name

​Good spot - I've correct this in the codebase and released 0.6.1 to PyPI.​

 

For more options, visit https://groups.google.com/groups/opt_out.
image.png
Reply all
Reply to author
Forward
0 new messages