From effba867dcd5a56b74300b3bf124cfd11e3f60f2 Mon Sep 17 00:00:00 2001 From: Bozidar Benko Date: Sun, 18 Mar 2012 20:21:30 +0100 Subject: [PATCH 1/4] Added validationMode support in CIM: updated create_payment_profile, CreateProfileRequest and CreateProfileRequest --- authorizenet/cim.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/authorizenet/cim.py b/authorizenet/cim.py index 110c920..05fb726 100644 --- a/authorizenet/cim.py +++ b/authorizenet/cim.py @@ -64,7 +64,7 @@ def create_form_data(data): def add_profile(customer_id, payment_form_data, billing_form_data, - shipping_form_data=None): + shipping_form_data=None, validation_mode=None): """ Add a customer profile with a single payment profile and return a tuple of the CIMResponse, profile ID, @@ -75,12 +75,15 @@ def add_profile(customer_id, payment_form_data, billing_form_data, payment_form_data -- dictionary with keys in CREDIT_CARD_FIELDS billing_form_data -- dictionary with keys in BILLING_FIELDS shipping_form_data -- dictionary with keys in SHIPPING_FIELDS + validation_mode -- 'testMode' or 'liveMode' """ kwargs = {'customer_id': customer_id, 'credit_card_data': extract_payment_form_data(payment_form_data), 'billing_data': extract_form_data(billing_form_data)} if shipping_form_data: kwargs['shipping_data'] = extract_form_data(shipping_form_data) + if validation_mode: + kwargs['validation_mode'] = validation_mode helper = CreateProfileRequest(**kwargs) response = helper.get_response() info = helper.customer_info @@ -103,7 +106,7 @@ def add_profile(customer_id, payment_form_data, billing_form_data, return {'response': response, 'profile_id': profile_id, 'payment_profile_ids': payment_profile_ids, - 'shipping_profile_ids': 'shipping_profile_ids'} + 'shipping_profile_ids': shipping_profile_ids} def update_payment_profile(profile_id, @@ -129,7 +132,7 @@ def update_payment_profile(profile_id, return response -def create_payment_profile(profile_id, payment_form_data, billing_form_data): +def create_payment_profile(profile_id, payment_form_data, billing_form_data, validation_mode=None): """ Create a customer payment profile and return a tuple of the CIMResponse and payment profile ID. @@ -138,12 +141,14 @@ def create_payment_profile(profile_id, payment_form_data, billing_form_data): profile_id -- unique gateway-assigned profile identifier payment_form_data -- dictionary with keys in CREDIT_CARD_FIELDS billing_form_data -- dictionary with keys in BILLING_FIELDS + validation_mode -- 'testMode' or 'liveMode' """ payment_data = extract_payment_form_data(payment_form_data) billing_data = extract_form_data(billing_form_data) helper = CreatePaymentProfileRequest(profile_id, billing_data, - payment_data) + payment_data, + validation_mode) response = helper.get_response() if response.success: payment_profile_id = helper.payment_profile_id @@ -329,7 +334,7 @@ def process_message_node(self, node): self.resultCode = f.childNodes[0].nodeValue elif f.localName == 'text': self.resultText = f.childNodes[0].nodeValue - + class BasePaymentProfileRequest(BaseRequest): def get_payment_profile_node(self, @@ -415,11 +420,18 @@ def get_shipping_profile_node(self, return shipping_profile -class CreateProfileRequest(BasePaymentProfileRequest, +class BaseValidationModeRequest(BaseRequest): + def get_validation_mode_node(self, + validation_mode=None, + node_name="validationMode"): + return self.get_text_node(node_name, validation_mode) + + +class CreateProfileRequest(BaseValidationModeRequest, BasePaymentProfileRequest, BaseShippingProfileRequest): def __init__(self, customer_id=None, customer_email=None, customer_description=None, billing_data=None, - shipping_data=None,credit_card_data=None): + shipping_data=None, credit_card_data=None, validation_mode=None): if not (customer_id or customer_email or customer_description): raise ValueError("%s requires one of 'customer_id', \ customer_email or customer_description" @@ -444,6 +456,10 @@ def __init__(self, customer_id=None, customer_email=None, profile_node.appendChild(shipping_profiles) self.root.appendChild(profile_node) + if validation_mode: + validation_mode_node = self.get_validation_mode_node(validation_mode) + self.root.appendChild(validation_mode_node) + def get_profile_node(self): profile = self.document.createElement("profile") for node_name, value in self.customer_info.items(): @@ -503,8 +519,8 @@ def __init__(self, self.root.appendChild(payment_profile) -class CreatePaymentProfileRequest(BasePaymentProfileRequest): - def __init__(self, profile_id, billing_data=None, credit_card_data=None): +class CreatePaymentProfileRequest(BaseValidationModeRequest, BasePaymentProfileRequest): + def __init__(self, profile_id, billing_data=None, credit_card_data=None, validation_mode=None): super(CreatePaymentProfileRequest, self).__init__("createCustomerPaymentProfileRequest") profile_id_node = self.get_text_node("customerProfileId", profile_id) @@ -513,6 +529,9 @@ def __init__(self, profile_id, billing_data=None, credit_card_data=None): "paymentProfile") self.root.appendChild(profile_id_node) self.root.appendChild(payment_profile) + if validation_mode: + validation_mode_node = self.get_validation_mode_node(validation_mode) + self.root.appendChild(validation_mode_node) def process_response(self, response): for e in response.childNodes[0].childNodes: From a5d5fc3263e79fa86cb52c09264bd9c7bf7ef3a4 Mon Sep 17 00:00:00 2001 From: Bozidar Benko Date: Sun, 1 Apr 2012 12:52:12 +0200 Subject: [PATCH 2/4] Added customer_email and customer_description to CIM add_profile --- authorizenet/cim.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/authorizenet/cim.py b/authorizenet/cim.py index 05fb726..d021fd2 100644 --- a/authorizenet/cim.py +++ b/authorizenet/cim.py @@ -64,7 +64,8 @@ def create_form_data(data): def add_profile(customer_id, payment_form_data, billing_form_data, - shipping_form_data=None, validation_mode=None): + shipping_form_data=None, customer_email=None, + customer_description=None, validation_mode=None): """ Add a customer profile with a single payment profile and return a tuple of the CIMResponse, profile ID, @@ -75,9 +76,13 @@ def add_profile(customer_id, payment_form_data, billing_form_data, payment_form_data -- dictionary with keys in CREDIT_CARD_FIELDS billing_form_data -- dictionary with keys in BILLING_FIELDS shipping_form_data -- dictionary with keys in SHIPPING_FIELDS + customer_email -- customer email + customer_description -- customer decription validation_mode -- 'testMode' or 'liveMode' """ kwargs = {'customer_id': customer_id, + 'customer_email': customer_email, + 'customer_description': customer_description, 'credit_card_data': extract_payment_form_data(payment_form_data), 'billing_data': extract_form_data(billing_form_data)} if shipping_form_data: From 1d62f1bbf36e2e18efc9dee83e9ec0dadbac05bb Mon Sep 17 00:00:00 2001 From: Bozidar Benko Date: Tue, 8 Jan 2013 11:18:41 +0100 Subject: [PATCH 3/4] Added optional email_customer parameter to CreateTransactionRequest. --- authorizenet/cim.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/authorizenet/cim.py b/authorizenet/cim.py index d021fd2..5e864bc 100644 --- a/authorizenet/cim.py +++ b/authorizenet/cim.py @@ -675,7 +675,8 @@ def __init__(self, shipping_profile_id=None, transaction_id=None, delimiter=None, - order_info=None): + order_info=None, + email_customer=None): """ Arguments: profile_id -- unique gateway-assigned profile identifier @@ -692,7 +693,7 @@ def __init__(self, delimiter -- Delimiter used for transaction response data order_info -- a dict with optional order parameters `invoice_number`, `description`, and `purchase_order_number` as keys. - + email_customer -- True or False, if passed, the api field will override configuration settings at Authorize.Net. Accepted transaction types: AuthOnly, AuthCapture, CaptureOnly, PriorAuthCapture, Refund, Void """ @@ -708,6 +709,7 @@ def __init__(self, self.delimiter = delimiter else: self.delimiter = getattr(settings, 'AUTHNET_DELIM_CHAR', "|") + self.email_customer = email_customer self.add_transaction_node() self.add_extra_options() if order_info: @@ -760,8 +762,10 @@ def add_order_info(self, invoice_number=None, self.type_node.appendChild(order_node) def add_extra_options(self): - extra_options_node = self.get_text_node("extraOptions", - "x_delim_data=TRUE&x_delim_char=%s" % self.delimiter) + extra_options = "x_delim_data=TRUE&x_delim_char=%s" % self.delimiter + if self.email_customer is not None: + extra_options += "&x_email_customer=%s" % self.email_customer + extra_options_node = self.get_text_node("extraOptions", extra_options) self.root.appendChild(extra_options_node) def create_response_object(self): From 3470e47a203f2d15c75aa370d3b98e71dc8eb0e6 Mon Sep 17 00:00:00 2001 From: Bozidar Benko Date: Tue, 8 Jan 2013 15:09:24 +0100 Subject: [PATCH 4/4] Added duplicate window setting to CreateTransactionRequest. --- authorizenet/cim.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/authorizenet/cim.py b/authorizenet/cim.py index 5e864bc..41cedd0 100644 --- a/authorizenet/cim.py +++ b/authorizenet/cim.py @@ -676,7 +676,8 @@ def __init__(self, transaction_id=None, delimiter=None, order_info=None, - email_customer=None): + email_customer=None, + duplicate_window=None): """ Arguments: profile_id -- unique gateway-assigned profile identifier @@ -694,6 +695,7 @@ def __init__(self, order_info -- a dict with optional order parameters `invoice_number`, `description`, and `purchase_order_number` as keys. email_customer -- True or False, if passed, the api field will override configuration settings at Authorize.Net. + duplicate_window -- set the number of seconds for duplicate window duration Accepted transaction types: AuthOnly, AuthCapture, CaptureOnly, PriorAuthCapture, Refund, Void """ @@ -710,6 +712,8 @@ def __init__(self, else: self.delimiter = getattr(settings, 'AUTHNET_DELIM_CHAR', "|") self.email_customer = email_customer + self.duplicate_window = duplicate_window + self.add_transaction_node() self.add_extra_options() if order_info: @@ -765,6 +769,8 @@ def add_extra_options(self): extra_options = "x_delim_data=TRUE&x_delim_char=%s" % self.delimiter if self.email_customer is not None: extra_options += "&x_email_customer=%s" % self.email_customer + if self.duplicate_window is not None: + extra_options += "&x_duplicate_window=%s" % self.duplicate_window extra_options_node = self.get_text_node("extraOptions", extra_options) self.root.appendChild(extra_options_node)