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