本文整理汇总了Python中samurai.payment_method.PaymentMethod.create方法的典型用法代码示例。如果您正苦于以下问题:Python PaymentMethod.create方法的具体用法?Python PaymentMethod.create怎么用?Python PaymentMethod.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类samurai.payment_method.PaymentMethod
的用法示例。
在下文中一共展示了PaymentMethod.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: store
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def store(self, credit_card, options=None):
if isinstance(credit_card, CreditCard):
if not self.validate_card(credit_card):
raise InvalidCard("Invalid Card")
payment_method = PaymentMethod.create(credit_card.number,
credit_card.verification_value,
credit_card.month, credit_card.year)
else:
# Using the token which has to be retained
payment_method = PaymentMethod.find(credit_card)
if payment_method.errors:
transaction_was_unsuccessful.send(sender=self,
type="store",
response=payment_method)
return {'status': 'FAILURE', 'response': payment_method}
response = payment_method.retain()
if response.errors:
transaction_was_unsuccessful.send(sender=self,
type="store",
response=response)
return {'status': 'FAILURE', 'response': response}
transaction_was_successful.send(sender=self,
type="store",
response=response)
return {'status': 'SUCCESS', 'response': response}
示例2: default_payment_method
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def default_payment_method(options={}):
data = {
'card_number': '4111111111111111',
'sandbox' : True,
'redirect_url' : 'http://test.host',
'merchant_key' : config.merchant_key,
'custom' : 'custom',
'first_name' : 'FirstName',
'last_name' : 'LastName',
'address_1' : '1000 1st Av',
'address_2' : '',
'city' : 'Chicago',
'state' : 'IL',
'zip' : '10101',
'card_number' : '4111111111111111',
'cvv' : '111',
'expiry_month' : '05',
'expiry_year' : '2014',
}
data.update(options)
return PaymentMethod.create(data.pop('card_number'),
data.pop('cvv'),
data.pop('expiry_month'),
data.pop('expiry_year'),
**data)
示例3: test_should_fail_on_blank_card_number
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def test_should_fail_on_blank_card_number(self):
params_tmp = params
params_tmp['card_number'] = ''
pm = PaymentMethod.create(**params_tmp)
self.assertFalse(pm.is_sensitive_data_valid)
err = {'context': 'input.card_number', 'key': 'is_blank', 'subclass': 'error'}
self.assertIn(err, pm.error_messages)
self.assertIn('The card number was blank.', pm.errors['input.card_number'])
示例4: test_should_return_failed_checksum_card_number
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def test_should_return_failed_checksum_card_number(self):
params_tmp = params
params_tmp['card_number'] = '4111-1111-1111-1234'
pm = PaymentMethod.create(**params_tmp)
self.assertFalse(pm.is_sensitive_data_valid)
err = {'context': 'input.card_number', 'key': 'failed_checksum', 'subclass': 'error'}
self.assertIn(err, pm.error_messages)
self.assertIn('The card number was invalid.', pm.errors['input.card_number'])
示例5: test_should_return_too_short_cvv
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def test_should_return_too_short_cvv(self):
params_tmp = params
params_tmp['cvv'] = '1'
pm = PaymentMethod.create(**params_tmp)
self.assertFalse(pm.is_sensitive_data_valid)
err = {'context': 'input.cvv', 'key': 'too_short', 'subclass': 'error'}
self.assertIn(err, pm.error_messages)
self.assertIn('The CVV was too short.', pm.errors['input.cvv'])
示例6: test_should_return_is_invalid_expiry_year
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def test_should_return_is_invalid_expiry_year(self):
params_tmp = params
params_tmp['expiry_year'] = 'abcd'
pm = PaymentMethod.create(**params_tmp)
self.assertFalse(pm.is_sensitive_data_valid)
self.assertFalse(pm.is_expiration_valid)
err = {'context': 'input.expiry_year', 'key': 'is_invalid', 'subclass': 'error'}
self.assertIn(err, pm.error_messages)
self.assertIn('The expiration year was invalid.', pm.errors['input.expiry_year'])
示例7: test_should_return_is_blank_expiry_month
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def test_should_return_is_blank_expiry_month(self):
params_tmp = params
params_tmp['expiry_month'] = ''
pm = PaymentMethod.create(**params_tmp)
self.assertFalse(pm.is_sensitive_data_valid)
self.assertFalse(pm.is_expiration_valid)
err = {'context': 'input.expiry_month', 'key': 'is_blank', 'subclass': 'error'}
self.assertIn(err, pm.error_messages)
self.assertIn('The expiration month was blank.', pm.errors['input.expiry_month'])
示例8: authorize
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def authorize(self, money, credit_card, options=None):
if not self.validate_card(credit_card):
raise InvalidCard("Invalid Card")
try:
from samurai.payment_method import PaymentMethod
from samurai.processor import Processor
pm = PaymentMethod.create(credit_card.number, credit_card.verification_value, credit_card.month, credit_card.year)
payment_method_token = pm.payment_method_token
response = Processor.authorize(payment_method_token, money)
except Exception, error:
return {'status': 'FAILURE', 'response': error}
示例9: authorize
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def authorize(self, money, credit_card, options=None):
payment_method_token = credit_card
if isinstance(credit_card, CreditCard):
if not self.validate_card(credit_card):
raise InvalidCard("Invalid Card")
pm = PaymentMethod.create(credit_card.number, credit_card.verification_value,
credit_card.month, credit_card.year)
payment_method_token = pm.payment_method_token
response = Processor.authorize(payment_method_token, money)
if response.errors:
return {'status': 'FAILURE', 'response': response}
return {'status': 'SUCCESS', 'response': response}
示例10: purchase
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def purchase(self, money, credit_card):
# Cases where token is directly sent for e.g. from Samurai.js
payment_method_token = credit_card
if isinstance(credit_card, CreditCard):
if not self.validate_card(credit_card):
raise InvalidCard("Invalid Card")
pm = PaymentMethod.create(credit_card.number, credit_card.verification_value,
credit_card.month, credit_card.year)
payment_method_token = pm.payment_method_token
response = Processor.purchase(payment_method_token, money)
if response.errors:
return {'status': 'FAILURE', 'response': response}
return {'status': 'SUCCESS', 'response': response}
示例11: test_find_should_be_successful
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def test_find_should_be_successful(self):
pm = PaymentMethod.create(**params)
token = pm.payment_method_token
pm = PaymentMethod.find(token)
self.assertTrue(self.pm.is_sensitive_data_valid)
self.assertTrue(self.pm.is_expiration_valid)
self.assertEqual(self.pm.first_name, params['first_name'])
self.assertEqual(self.pm.last_name, params['last_name'])
self.assertEqual(self.pm.address_1, params['address_1'])
self.assertEqual(self.pm.address_2, params['address_2'])
self.assertEqual(self.pm.city, params['city'])
self.assertEqual(self.pm.state, params['state'])
self.assertEqual(self.pm.zip, params['zip'])
self.assertEqual(self.pm.last_four_digits, params['card_number'][-4:])
self.assertEqual(self.pm.expiry_month, int(params['expiry_month']))
self.assertEqual(self.pm.expiry_year, int(params['expiry_year']))
示例12: default_payment_method
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def default_payment_method(options={}):
data = {
'card_number': '4111111111111111',
'cvv': '111',
'expiry_month': '07',
'expiry_year': '14',
'first_name': 'first_name',
'last_name': 'last_name',
'sandbox': True
}
data.update(options)
return PaymentMethod.create(data.pop('card_number'),
data.pop('cvv'),
data.pop('expiry_month'),
data.pop('expiry_year'),
**data)
示例13: purchase
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def purchase(request):
if request.method == "POST":
data = request.POST
token = PaymentMethod.create(data.get('card_number'), data.get('cvv'), data.get('expiry_month'),
data.get('expiry_year'), first_name=data.get('first_name'),
last_name=data.get('last_name'))
trans = Processor.purchase(token.payment_method_token, 10)
if trans.errors:
errors = parse_error(trans.errors)
for err in errors:
messages.error(request, err, fail_silently=True)
return redirect('/server_to_server/payment_form')
else:
messages.success(request, 'Purchase Successful.', fail_silently=True)
return render_to_response('/server_to_server/receipt.html')
else:
return redirect('/server_to_server/payment_form')
示例14: test_update_should_be_successful_preserving_sensitive_data
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def test_update_should_be_successful_preserving_sensitive_data(self):
params_tmp = paramsx
params_tmp['card_number'] = '****************'
params_tmp['cvv'] = '***'
pm = PaymentMethod.create(**params)
pm = pm.update(**paramsx)
self.assertTrue(pm.is_expiration_valid)
self.assertEqual(pm.first_name, params_tmp['first_name'])
self.assertEqual(pm.last_name, params_tmp['last_name'])
self.assertEqual(pm.address_1, params_tmp['address_1'])
self.assertEqual(pm.address_2, params_tmp['address_2'])
self.assertEqual(pm.city, params_tmp['city'])
self.assertEqual(pm.state, params_tmp['state'])
self.assertEqual(pm.zip, params_tmp['zip'])
self.assertEqual(pm.last_four_digits, '1111')
self.assertEqual(pm.expiry_month, int(params_tmp['expiry_month']))
self.assertEqual(pm.expiry_year, int(params_tmp['expiry_year']))
示例15: charge_setup
# 需要导入模块: from samurai.payment_method import PaymentMethod [as 别名]
# 或者: from samurai.payment_method.PaymentMethod import create [as 别名]
def charge_setup(self, card, billing_info):
"""
standard setup, used for charges
"""
billing_info = self.translate(billing_info)
# use the card + extra data- send it to samurai for storage and tokenization
card._exp_yr_style = True
super(Samurai, self).use_credit_card(card)
pm = PaymentMethod.create(
card.number,
card.verification_value,
card.exp_month, card.exp_year, **billing_info)
debug_string = " paython.gateways.samurai_ff.charge_setup() -- response on setting pm"
logger.debug(debug_string.center(80, '='))
logger.debug(dir(pm))
if pm.errors:
raise DataValidationError('Invalid Card Data: %s' % pm.errors[pm.error_messages[0]['context']][0])
return pm.payment_method_token