def setUp(self): self.paypal = AdaptiveAccounts(API_USERNAME, API_PASSWORD, API_SIGNATURE, API_APPLICATION_ID, API_EMAIL, sandbox=True) self.paypal.debug = False
class TestAdaptiveAccounts(TestCase): notification_url = "http://notify.me" return_url = "http://return.me" def setUp(self): self.paypal = AdaptiveAccounts(API_USERNAME, API_PASSWORD, API_SIGNATURE, API_APPLICATION_ID, API_EMAIL, sandbox=True) self.paypal.debug = False def test_create_account(self): response = self.paypal.create_account( accountType='Premier', emailAddress='*****@*****.**', name={ 'firstName': 'John', 'lastName': 'Doe' }, dateOfBirth='1968-01-01', address={ 'line1': '90210, Melrose Place', 'city': 'Beverly Hills', 'postalCode': '90210', 'state': 'CA', 'countryCode': 'US' }, contactPhoneNumber='888-555-1212', currencyCode='USD', citizenshipCountryCode='US', preferredLanguageCode='en_US', notificationURL=self.notification_url, createAccountWebOptions={'returnUrl': self.return_url}) self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertEquals(response['execStatus'], "COMPLETED") self.assertTrue(response.has_key('createAccountKey')) def test_add_bank_account(self): response = self.paypal.add_bank_account( emailAddress='*****@*****.**', confirmationType='WEB', bankCountryCode='US') self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertEquals(response['execStatus'], "COMPLETED") def test_add_payment_card(self): response = self.paypal.add_payment_card( emailAddress="*****@*****.**", billingAddress={ 'line1': '90210, Melrose Place', 'city': 'Beverly Hills', 'postalCode': '90210', 'state': 'CA', 'countryCode': 'US' }, cardType='Visa', cardNumber=VISA_NUMBER, confirmationType='WEB', nameOnCard={ 'firstName': 'John', 'lastName': 'Doe' }, expirationDate={ 'month': VISA_EXPIRATION[:2], 'year': VISA_EXPIRATION[2:6] }) self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertEquals(response['execStatus'], "WEB_URL_VERIFICATION_NEEDED") self.assertTrue(response.has_key('fundingSourceKey')) def test_set_funding_source_confirmed(self): fundingSourceKey = self.paypal.add_payment_card( emailAddress="*****@*****.**", billingAddress={ 'line1': '90210, Melrose Place', 'city': 'Beverly Hills', 'postalCode': '90210', 'state': 'CA', 'countryCode': 'US' }, cardType='Visa', cardNumber='4914240823748958', confirmationType='WEB', nameOnCard={ 'firstName': 'Joey', 'lastName': 'Triviani' }, expirationDate={ 'month': '09', 'year': '2015' })['fundingSourceKey'] response = self.paypal.set_funding_source_confirmed( emailAddress="*****@*****.**", fundingSourceKey=fundingSourceKey) self.assertEquals(response['responseEnvelope']['ack'], "Success") def test_get_verified_status(self): response = self.paypal.get_verified_status( emailAddress="*****@*****.**", firstName='John', lastName='Doe', matchCriteria='NAME') self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertEquals(response['accountStatus'], 'VERIFIED') def test_get_user_agreement(self): response = self.paypal.get_user_agreement(languageCode='en_US', countryCode='US') self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertTrue('PayPal' in response['agreement'])
class TestAdaptiveAccounts(TestCase): notification_url = "http://notify.me" return_url = "http://return.me" def setUp(self): self.paypal = AdaptiveAccounts(API_USERNAME, API_PASSWORD, API_SIGNATURE, API_APPLICATION_ID, API_EMAIL, sandbox=True) self.paypal.debug = False def test_create_account(self): response = self.paypal.create_account( accountType = 'Premier', emailAddress = '*****@*****.**', name = { 'firstName':'John', 'lastName':'Doe' }, dateOfBirth = '1968-01-01', address = { 'line1':'90210, Melrose Place', 'city':'Beverly Hills', 'postalCode':'90210', 'state':'CA', 'countryCode':'US' }, contactPhoneNumber = '888-555-1212', currencyCode = 'USD', citizenshipCountryCode = 'US', preferredLanguageCode = 'en_US', notificationURL = self.notification_url, createAccountWebOptions = { 'returnUrl':self.return_url } ) self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertEquals(response['execStatus'], "COMPLETED") self.assertTrue(response.has_key('createAccountKey')) def test_add_bank_account(self): response = self.paypal.add_bank_account( emailAddress = '*****@*****.**', confirmationType = 'WEB', bankCountryCode = 'US' ) self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertEquals(response['execStatus'], "COMPLETED") def test_add_payment_card(self): response = self.paypal.add_payment_card( emailAddress = "*****@*****.**", billingAddress = { 'line1':'90210, Melrose Place', 'city':'Beverly Hills', 'postalCode':'90210', 'state':'CA', 'countryCode':'US' }, cardType = 'Visa', cardNumber = VISA_NUMBER, confirmationType = 'WEB', nameOnCard = { 'firstName':'John', 'lastName':'Doe' }, expirationDate = { 'month':VISA_EXPIRATION[:2], 'year':VISA_EXPIRATION[2:6] } ) self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertEquals(response['execStatus'], "WEB_URL_VERIFICATION_NEEDED") self.assertTrue(response.has_key('fundingSourceKey')) def test_set_funding_source_confirmed(self): fundingSourceKey = self.paypal.add_payment_card( emailAddress = "*****@*****.**", billingAddress = { 'line1':'90210, Melrose Place', 'city':'Beverly Hills', 'postalCode':'90210', 'state':'CA', 'countryCode':'US' }, cardType = 'Visa', cardNumber = '4914240823748958', confirmationType = 'WEB', nameOnCard = { 'firstName':'Joey', 'lastName':'Triviani' }, expirationDate = { 'month':'09', 'year':'2015' } )['fundingSourceKey'] response = self.paypal.set_funding_source_confirmed( emailAddress = "*****@*****.**", fundingSourceKey = fundingSourceKey ) self.assertEquals(response['responseEnvelope']['ack'], "Success") def test_get_verified_status(self): response = self.paypal.get_verified_status( emailAddress = "*****@*****.**", firstName = 'John', lastName = 'Doe', matchCriteria = 'NAME' ) self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertEquals(response['accountStatus'], 'VERIFIED') def test_get_user_agreement(self): response = self.paypal.get_user_agreement( languageCode = 'en_US', countryCode = 'US' ) self.assertEquals(response['responseEnvelope']['ack'], "Success") self.assertTrue('PayPal' in response['agreement'])
from django.core.urlresolvers import reverse from django.contrib.sites.models import Site from paypalx import PaypalError, AdaptivePayments, AdaptiveAccounts from payments.abstract_payment import AbstractPayment from eloue.utils import convert_from_xpf import logbook log = logbook.Logger('eloue.accounts') __all__ = ['PaypalError', 'accounts'] accounts = AdaptiveAccounts(settings.PAYPAL_API_USERNAME, settings.PAYPAL_API_PASSWORD, settings.PAYPAL_API_SIGNATURE, settings.PAYPAL_API_APPLICATION_ID, settings.PAYPAL_API_EMAIL, sandbox=settings.USE_PAYPAL_SANDBOX) def verify_paypal_account(email, first_name, last_name): try: response = accounts.get_verified_status(emailAddress=email, firstName=first_name, lastName=last_name, matchCriteria="NAME") return response['accountStatus'] except PaypalError, e: log.error(e) return "INVALID"