Skip to content

Commit

Permalink
Adding PayPal transaction support.
Browse files Browse the repository at this point in the history
  • Loading branch information
vcatalano committed Sep 14, 2016
1 parent 3dcde60 commit f011cf1
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 24 deletions.
9 changes: 4 additions & 5 deletions authorize/apis/payment_profile_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@

class PaymentProfileAPI(BaseAPI):

def details(self, customer_id, payment_id, unmask_expiry=False):
return self.api._make_call(self._details_request(customer_id, payment_id, unmask_expiry))
def details(self, customer_id, payment_id):
return self.api._make_call(self._details_request(customer_id, payment_id))

def delete(self, customer_id, payment_id):
self.api._make_call(self._delete_request(customer_id, payment_id))

# The following methods generate the XML for the corresponding API calls.
# This makes unit testing each of the calls easier.
def _details_request(self, customer_id, payment_id, unmask_expiry=False):
def _details_request(self, customer_id, payment_id):
request = self.api._base_request('getCustomerPaymentProfileRequest')
E.SubElement(request, 'customerProfileId').text = customer_id
E.SubElement(request, 'customerPaymentProfileId').text = payment_id
if unmask_expiry:
E.SubElement(request, 'unmaskExpirationDate').text = 'true'
E.SubElement(request, 'unmaskExpirationDate').text = 'true'
return request

def _delete_request(self, customer_id, payment_id):
Expand Down
8 changes: 8 additions & 0 deletions authorize/apis/recurring_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def create(self, params={}):
def details(self, subscription_id):
return self.api._make_call(self._details_request(subscription_id))

def status(self, subscription_id):
return self.api._make_call(self._status_request(subscription_id))

def update(self, subscription_id, params={}):
subscription = self._deserialize(UpdateRecurringSchema().bind(), params)
return self.api._make_call(self._update_request(subscription_id, subscription))
Expand Down Expand Up @@ -56,6 +59,11 @@ def _create_request(self, subscription={}):
return self._make_xml('ARBCreateSubscriptionRequest', None, params=subscription)

def _details_request(self, subscription_id):
request = self.api._base_request('ARBGetSubscriptionRequest')
E.SubElement(request, 'subscriptionId').text = subscription_id
return request

def _status_request(self, subscription_id):
request = self.api._base_request('ARBGetSubscriptionStatusRequest')
E.SubElement(request, 'subscriptionId').text = subscription_id
return request
Expand Down
4 changes: 4 additions & 0 deletions authorize/recurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def create(params={}):
def details(subscription_id):
return Configuration.api.recurring.details(subscription_id)

@staticmethod
def status(subscription_id):
return Configuration.api.recurring.status(subscription_id)

@staticmethod
def update(subscription_id, params={}):
return Configuration.api.recurring.update(subscription_id, params)
Expand Down
1 change: 1 addition & 0 deletions tests/test_bank_account_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
</merchantAuthentication>
<customerProfileId>1234567890</customerProfileId>
<customerPaymentProfileId>0987654321</customerPaymentProfileId>
<unmaskExpirationDate>true</unmaskExpirationDate>
</getCustomerPaymentProfileRequest>'''

UPDATE_BANK_ACCOUNT_REQUEST = '''
Expand Down
17 changes: 0 additions & 17 deletions tests/test_credit_card_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,6 @@

DETAILS_CREDIT_CARD_REQUEST = '''
<?xml version="1.0" ?>
<getCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>8s8tVnG5t</name>
<transactionKey>5GK7mncw8mG2946z</transactionKey>
</merchantAuthentication>
<customerProfileId>1234567890</customerProfileId>
<customerPaymentProfileId>0987654321</customerPaymentProfileId>
</getCustomerPaymentProfileRequest>
'''

DETAILS_CREDIT_CARD_REQUEST_UNMASKED_EXPIRY = '''
<?xml version="1.0" ?>
<getCustomerPaymentProfileRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>8s8tVnG5t</name>
Expand Down Expand Up @@ -218,11 +206,6 @@ def test_details_credit_card_request(self):
request_string = prettify(request_xml)
self.assertEqual(request_string, DETAILS_CREDIT_CARD_REQUEST.strip())

def test_details_credit_card_request_unmask_expiry(self):
request_xml = Configuration.api.credit_card._details_request('1234567890', '0987654321', True)
request_string = prettify(request_xml)
self.assertEqual(request_string, DETAILS_CREDIT_CARD_REQUEST_UNMASKED_EXPIRY.strip())

def test_update_credit_card_request(self):
request_xml = Configuration.api.credit_card._update_request('1234567890', '0987654321', CREDIT_CARD)
request_string = prettify(request_xml)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_live_credit_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
PAYMENT_RESULT = {
'credit_card': {
'card_number': 'XXXX1111',
'expiration_date': 'XXXX',
'expiration_date': '{0}-04'.format(date.today().year + 1),
'card_type': 'Visa'
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/test_live_recurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ def test_live_recurring(self):
result = Recurring.create(recurring)
subscription_id = result.subscription_id

# Read subscription status
Recurring.details(subscription_id)

Recurring.status(subscription_id)

# Update subscription information
recurring = UPDATE_RECURRING.copy()
recurring['amount'] = random.randrange(100, 100000) / 100.0
Expand Down
16 changes: 16 additions & 0 deletions tests/test_recurring_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@

DETAILS_RECURRING_REQUEST = '''
<?xml version="1.0" ?>
<ARBGetSubscriptionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>8s8tVnG5t</name>
<transactionKey>5GK7mncw8mG2946z</transactionKey>
</merchantAuthentication>
<subscriptionId>0932576929034</subscriptionId>
</ARBGetSubscriptionRequest>
'''

STATUS_RECURRING_REQUEST = '''
<?xml version="1.0" ?>
<ARBGetSubscriptionStatusRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>8s8tVnG5t</name>
Expand Down Expand Up @@ -328,6 +339,11 @@ def test_details_recurring_request(self):
request_string = prettify(request_xml)
self.assertEqual(request_string, DETAILS_RECURRING_REQUEST.strip())

def test_status_recurring_request(self):
request_xml = Configuration.api.recurring._status_request('0932576929034')
request_string = prettify(request_xml)
self.assertEqual(request_string, STATUS_RECURRING_REQUEST.strip())

def test_update_recurring_request(self):
request_xml = Configuration.api.recurring._update_request('0932576929034', UPDATE_RECURRING)
request_string = prettify(request_xml)
Expand Down

0 comments on commit f011cf1

Please sign in to comment.