Skip to content

Commit

Permalink
POC recurring payments works!
Browse files Browse the repository at this point in the history
  • Loading branch information
codeinthehole committed Apr 18, 2013
1 parent 300d9c6 commit e239980
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion paypal/express/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_paypal_url(basket, shipping_methods, user=None, shipping_address=None,
update_url = None
if shipping_methods:
update_url = '%s://%s%s' % (scheme, host, reverse('paypal-shipping-options',
kwargs={'basket_id': basket.id}))
kwargs={'basket_id': basket.id}))

# Pass a default billing address is there is one. This means PayPal can
# pre-fill the registration form.
Expand Down
20 changes: 20 additions & 0 deletions paypal/express/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ def set_txn(basket, shipping_methods, currency, return_url, cancel_url, update_u
params['PAYMENTREQUEST_0_AMT'] = _format_currency(
params['PAYMENTREQUEST_0_AMT'])

# Test recurring billing
params['L_BILLINGTYPE0'] = 'RecurringPayments'
params['L_BILLINGAGREEMENTDESCRIPTION0'] = 'Dave magazone subscription'

txn = _fetch_response(SET_EXPRESS_CHECKOUT, params)

# Construct return URL
Expand Down Expand Up @@ -351,6 +355,8 @@ def do_void(txn_id, note=None):

FULL_REFUND = 'Full'
PARTIAL_REFUND = 'Partial'


def refund_txn(txn_id, is_partial=False, amount=None, currency=None):
params = {
'TRANSACTIONID': txn_id,
Expand All @@ -360,3 +366,17 @@ def refund_txn(txn_id, is_partial=False, amount=None, currency=None):
params['AMT'] = amount
params['CURRENCYCODE'] = currency
return _fetch_response(REFUND_TRANSACTION, params)


def create_recurring_payments_profile(token):
params = {
'TOKEN': token,
'PROFILESTARTDATE': '2013-05-05T03:00:00',
'DESC': 'Dave magazone subscription',
'BILLINGPERIOD': 'Month',
'BILLINGFREQUENCY': '6',
'CURRENCYCODE': 'GBP',
'AMT': '10.55',
}
return _fetch_response('CreateRecurringPaymentsProfile', params)

4 changes: 4 additions & 0 deletions paypal/express/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from oscar.apps.shipping.methods import FixedPrice

from paypal.express.facade import get_paypal_url, fetch_transaction_details, confirm_transaction
from paypal.express.gateway import create_recurring_payments_profile
from paypal.exceptions import PayPalError

ShippingAddress = get_model('order', 'ShippingAddress')
Expand Down Expand Up @@ -205,6 +206,9 @@ def handle_payment(self, order_number, total_incl_tax, **kwargs):
if not txn.is_successful:
raise UnableToTakePayment()

# Create recurring profile thing
create_recurring_payments_profile(token)

# Record payment source and event
source_type, is_created = SourceType.objects.get_or_create(name='PayPal')
source = Source(source_type=source_type,
Expand Down
6 changes: 3 additions & 3 deletions sandbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@

# These are the standard PayPal sandbox details from the docs - but I don't
# think you can get access to the merchant dashboard.
PAYPAL_API_USERNAME = 'sdk-three_api1.sdk.com'
PAYPAL_API_PASSWORD = 'QFZCWN5HZM8VBG7Q'
PAYPAL_API_SIGNATURE = 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU'
#PAYPAL_API_USERNAME = 'sdk-three_api1.sdk.com'
#PAYPAL_API_PASSWORD = 'QFZCWN5HZM8VBG7Q'
#PAYPAL_API_SIGNATURE = 'A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU'

PAYPAL_PAYFLOW_CURRENCY = 'GBP'

0 comments on commit e239980

Please sign in to comment.