Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation mode, email and description in CIM #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 47 additions & 13 deletions authorizenet/cim.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def create_form_data(data):


def add_profile(customer_id, payment_form_data, billing_form_data,
shipping_form_data=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,
Expand All @@ -75,12 +76,19 @@ 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:
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
Expand All @@ -103,7 +111,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,
Expand All @@ -129,7 +137,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.
Expand All @@ -138,12 +146,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
Expand Down Expand Up @@ -329,7 +339,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,
Expand Down Expand Up @@ -415,11 +425,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"
Expand All @@ -444,6 +461,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():
Expand Down Expand Up @@ -503,8 +524,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)
Expand All @@ -513,6 +534,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:
Expand Down Expand Up @@ -651,7 +675,9 @@ def __init__(self,
shipping_profile_id=None,
transaction_id=None,
delimiter=None,
order_info=None):
order_info=None,
email_customer=None,
duplicate_window=None):
"""
Arguments:
profile_id -- unique gateway-assigned profile identifier
Expand All @@ -668,7 +694,8 @@ 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.
duplicate_window -- set the number of seconds for duplicate window duration
Accepted transaction types:
AuthOnly, AuthCapture, CaptureOnly, PriorAuthCapture, Refund, Void
"""
Expand All @@ -684,6 +711,9 @@ def __init__(self,
self.delimiter = delimiter
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:
Expand Down Expand Up @@ -736,8 +766,12 @@ 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
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)

def create_response_object(self):
Expand Down