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

Allow shipping address to be sent to Paypal #132

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ PayPal
:param client_id: Client ID assigned by PayPal or your email address
:param secret: Secret assigned by PayPal
:param endpoint: The API endpoint to use. For the production environment, use ``'https://api.paypal.com'`` instead
:param send_shipping_address: Whether to send a shipping address to Paypal. If ``True``, requires a method ``get_shipping_address_for_paypal`` on the ``Payment`` model which returns the address as a dict.
:param capture: Whether to capture the payment automatically. See :ref:`capture-payments` for more details.


Expand All @@ -210,6 +211,7 @@ Example::
'client_id': '[email protected]',
'secret': 'iseedeadpeople',
'endpoint': 'https://api.sandbox.paypal.com',
'send_shipping_address': False,
'capture': False})}

.. class:: payments.paypal.PaypalCardProvider(client_id, secret[, endpoint='https://api.sandbox.paypal.com'])
Expand Down Expand Up @@ -264,7 +266,7 @@ Sofort.com
:param id: Your sofort.com user id
:param key: Your secret key
:param project_id: Your sofort.com project id
:param endpoint: The API endpoint to use.
:param endpoint: The API endpoint to use.

Example::

Expand Down
37 changes: 27 additions & 10 deletions payments/paypal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ class PaypalProvider(BasicProvider):
paypal.com payment provider
'''
def __init__(self, client_id, secret,
endpoint='https://api.sandbox.paypal.com', **kwargs):
endpoint='https://api.sandbox.paypal.com',
send_shipping_address=False, **kwargs):
self.secret = secret
self.client_id = client_id
self.endpoint = endpoint
self.send_shipping_address = send_shipping_address
self.oauth2_url = self.endpoint + '/v1/oauth2/token'
self.payments_url = self.endpoint + '/v1/payments/payment'
self.payment_execute_url = self.payments_url + '/%(id)s/execute/'
Expand Down Expand Up @@ -180,17 +182,32 @@ def get_transactions_data(self, payment):
tax = payment.tax.quantize(CENTS, rounding=ROUND_HALF_UP)
delivery = payment.delivery.quantize(
CENTS, rounding=ROUND_HALF_UP)

if self.send_shipping_address:
item_list = {
'items': items,
'shipping_address': payment.get_shipping_address_for_paypal()
}
else:
item_list = {'items': items}

data = {
'intent': 'sale' if self._capture else 'authorize',
'transactions': [{'amount': {
'total': str(total),
'currency': payment.currency,
'details': {
'subtotal': str(sub_total),
'tax': str(tax),
'shipping': str(delivery)}},
'item_list': {'items': items},
'description': payment.description}]}
'transactions': [{
'amount': {
'total': str(total),
'currency': payment.currency,
'details': {
'subtotal': str(sub_total),
'tax': str(tax),
'shipping': str(delivery)
}
},
'item_list': item_list,
'description': payment.description
}]
}

return data

def get_product_data(self, payment, extra_data=None):
Expand Down