forked from agiliq/merchant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added purchase and authorize method of samurai
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |