Permalink
Browse files

added more methods to samurai

  • Loading branch information...
1 parent 6bec806 commit 2c3666018d629e21b06e30aac17621771bd047b8 @hayyat committed Dec 29, 2011
Showing with 43 additions and 15 deletions.
  1. +43 −15 billing/gateways/samurai_gateway.py
@@ -4,6 +4,7 @@
import samurai
from django.conf import settings
+
class SamuraiGateway(Gateway):
supported_cardtypes = [Visa, MasterCard, AmericanExpress, Discover]
supported_countries = ['US']
@@ -18,20 +19,21 @@ def __init__(self):
config.processor_token = settings.SAMURAI_PROCESSOR_TOKEN
self.samurai = samurai
- def purchase(self, money, credit_card):
+ 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)
+ 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):
+
+ def authorize(self, money, credit_card, options=None):
if not self.validate_card(credit_card):
raise InvalidCard("Invalid Card")
try:
@@ -43,26 +45,52 @@ def authorize(self, money, credit_card, options = None):
except Exception, error:
return {'status': 'FAILURE', 'response': error}
return {'status': 'SUCCESS', 'response': response}
-
- def capture(self, money, identification, options = None):
+
+ def capture(self, money, identification, options=None):
from samurai.transaction import Transaction
trans = Transaction.find(identification)
if not trans.errors:
new_trans = trans.capture(money)
return{'status': "SUCCESS", "response": new_trans}
else:
- return{"status":"FAILED", "response": trans.errors}
+ return{"status": "FAILURE", "response": trans.errors}
- def reverse(self, money, authorization, options=None):
- if not authorization.errors:
- new_trans = authorization.reverse(money)
+ def reverse(self, money, identification, options=None):
+ from samurai.transaction import Transaction
+ trans = Transaction.find(identification)
+ if not trans.errors:
+ new_trans = trans.reverse(money)
return{'status': "SUCCESS", "response": new_trans}
else:
- return{"status":"FAILED", "response": authorization.errors}
+ return{"status": "FAILURE", "response": trans.errors}
- def void(self, authorization, options=None):
- if not authorization.errors:
- new_trans = authorization.void()
+ def void(self, identification, options=None):
+ from samurai.transaction import Transaction
+ trans = Transaction.find(identification)
+ if not trans.errors:
+ new_trans = trans.void()
return{'status': "SUCCESS", "response": new_trans}
else:
- return{"status":"FAILED", "response": authorization.errors}
+ return{"status": "FAILURE", "response": trans.errors}
+
+ def credit(self, money, identification, options=None):
+ from samurai.transaction import Transaction
+ trans = Transaction.find(identification)
+ if not trans.errors:
+ new_trans = trans.credit(money)
+ return{'status': "SUCCESS", "response": new_trans}
+ else:
+ return{"status": "FAILURE", "response": trans.errors}
+
+ def store(self, credit_card, options=None):
+ 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)
+ response = pm.retain()
+ return {'status': 'SUCCESS', 'response': response}
+
+ def unstore(self, identification, options=None):
+ from samurai.payment_method import PaymentMethod
+ payment_method = PaymentMethod.find(identification)
+ payment_method = payment_method.redact()
+ return payment_method

0 comments on commit 2c36660

Please sign in to comment.