Skip to content

Commit

Permalink
added purchase and authorize method of samurai
Browse files Browse the repository at this point in the history
  • Loading branch information
hayyat committed Dec 27, 2011
1 parent 1f2a818 commit c6bd550
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions billing/gateways/samurai_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from billing import Gateway
from billing.utils.credit_card import InvalidCard, Visa, MasterCard, \
AmericanExpress, Discover
import samurai
from django.conf import settings

class SamuraiGateway(Gateway):
supported_cardtypes = [Visa, MasterCard, AmericanExpress, Discover]
supported_countries = ['US']
default_currency = "USD"
homepage_url = "https://samurai.feefighters.com/"
display_name = "Samurai"

def __init__(self):
import samurai.config as config
config.merchant_key = settings.SAMURAI_MERCHANT_KEY
config.merchant_password = settings.SAMURAI_MERCHANT_PASSWORD
config.processor_token = settings.SAMURAI_PROCESSOR_TOKEN
self.samurai = samurai

def purchase(self, money, credit_card):
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.purchase(payment_method_token, money)
except Exception, error:
return {'status': 'FAILURE', 'response': error}
return {'status': 'SUCCESS', 'response': response}

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}
return {'status': 'SUCCESS', 'response': response}

0 comments on commit c6bd550

Please sign in to comment.