def create(self, auth_token, po, card_type, card_number, exp_date, amount, invoice_number, first_name, last_name, address_label, city, state, zip, country, cvv2, optional_parameters=None): """ Create a Payment @param po Foreign Key for a purchase order @param card_type One of: Visa, MasterCard, Discover, Amex @param card_number Credit Card number @param exp_date Expiration Date as four integers MMYY @param amount Amount in cents @param invoice_number Invoice Number @param first_name First name on the card @param last_name Last name on the card @param address_label Address label for the card @param city City for the card @param state State for the card @param zip Zip Code for the card @param country 2-letter country code as defined in ISO-3166 @param cvv2 CVV2 value. @param optional_parameters sales_tax @return Reference to newly created Payment """ if optional_parameters is None: optional_parameters = {} ip = auth_token.ip sales_tax = optional_parameters['sales_tax'] if 'sales_tax' in optional_parameters else 0 local_po = self._find_by_id(po, facade.models.PurchaseOrder) # Run the list of pre-transaction hooks for transaction_hook in self.my_pre_transaction_hooks: transaction_hook(local_po) t = txn_data(card_type, card_number, exp_date, amount, invoice_number, first_name, last_name, address_label, city, state, zip, country, ip, cvv2, sales_tax) blame = facade.managers.BlameManager().create(auth_token) r = process_txn(t).charge() p = self.my_django_model(amount = amount, transaction_id = r['transaction_id'], purchase_order = local_po, card_number = card_number[-4:], result_message = r['result_message'], blame = blame, card_type = card_type, exp_date = exp_date, invoice_number = invoice_number, first_name = first_name, last_name = last_name, address_label = address_label, city = city, state = state, zip = zip, country = country, sales_tax = sales_tax) p.save() # Run the list of post transaction hooks for transaction_hook in self.my_post_transaction_hooks: transaction_hook(local_po) return p
def refund(self, auth_token, payment, amount, card_number=None): """ Make a refund @param payment Primary Key for a Payment @param amount Amount in cents @param card_number Card number, only required for certain merchant service providers @return Sucessfully refunded amount """ p = self._find_by_id(payment) if card_number != None: p.card_number = card_number ip = auth_token.ip blame = facade.managers.BlameManager().create(auth_token) r = facade.models.Refund(payment=p, blame=blame, amount=amount) self.authorizer.check_create_permissions(auth_token, r) t = txn_data(card_type=p.card_type, card_number=p.card_number, exp_date=p.exp_date, amount=amount, invoice_number=p.invoice_number, first_name=p.first_name, last_name=p.last_name, address_label=p.address_label, city=p.city, state=p.state, zip=p.zip, country=p.country, ip=ip, sales_tax=p.sales_tax, transaction_id=p.transaction_id) credit = process_txn(t).credit() r.result_message = credit['result_message'] r.transaction_id = credit['transaction_id'] r.save() return r.amount
def refund(self, auth_token, payment, amount, card_number=None): """ Make a refund @param payment Primary Key for a Payment @param amount Amount in cents @param card_number Card number, only required for certain merchant service providers @return Sucessfully refunded amount """ p = self._find_by_id(payment) if card_number != None: p.card_number = card_number ip = auth_token.ip blame = facade.managers.BlameManager().create(auth_token) r = facade.models.Refund(payment = p, blame = blame, amount = amount) self.authorizer.check_create_permissions(auth_token, r) t = txn_data(card_type = p.card_type, card_number = p.card_number, exp_date = p.exp_date, amount = amount, invoice_number = p.invoice_number, first_name = p.first_name, last_name = p.last_name, address_label = p.address_label, city = p.city, state = p.state, zip = p.zip, country = p.country, ip = ip, sales_tax = p.sales_tax, transaction_id = p.transaction_id) credit = process_txn(t).credit() r.result_message = credit['result_message'] r.transaction_id = credit['transaction_id'] r.save() return r.amount
def create(self, auth_token, po, card_type, card_number, exp_date, amount, invoice_number, first_name, last_name, address_label, city, state, zip, country, cvv2, optional_parameters=None): """ Create a Payment @param po Foreign Key for a purchase order @param card_type One of: Visa, MasterCard, Discover, Amex @param card_number Credit Card number @param exp_date Expiration Date as four integers MMYY @param amount Amount in cents @param invoice_number Invoice Number @param first_name First name on the card @param last_name Last name on the card @param address_label Address label for the card @param city City for the card @param state State for the card @param zip Zip Code for the card @param country 2-letter country code as defined in ISO-3166 @param cvv2 CVV2 value. @param optional_parameters sales_tax @return Reference to newly created Payment """ if optional_parameters is None: optional_parameters = {} ip = auth_token.ip sales_tax = optional_parameters[ 'sales_tax'] if 'sales_tax' in optional_parameters else 0 local_po = self._find_by_id(po, facade.models.PurchaseOrder) # Run the list of pre-transaction hooks for transaction_hook in self.my_pre_transaction_hooks: transaction_hook(local_po) t = txn_data(card_type, card_number, exp_date, amount, invoice_number, first_name, last_name, address_label, city, state, zip, country, ip, cvv2, sales_tax) blame = facade.managers.BlameManager().create(auth_token) r = process_txn(t).charge() p = self.my_django_model(amount=amount, transaction_id=r['transaction_id'], purchase_order=local_po, card_number=card_number[-4:], result_message=r['result_message'], blame=blame, card_type=card_type, exp_date=exp_date, invoice_number=invoice_number, first_name=first_name, last_name=last_name, address_label=address_label, city=city, state=state, zip=zip, country=country, sales_tax=sales_tax) p.save() # Run the list of post transaction hooks for transaction_hook in self.my_post_transaction_hooks: transaction_hook(local_po) return p