def create_payment_profile_node(self, node_name, billing_info, credit_card_info, **kwargs): # make payment_profiles node payment_profiles_node = ET.Element(node_name) # bill_to billing_info = to_camel_case(billing_info) if billing_info and (type(billing_info) is dict): bill_to_node = ET.SubElement(payment_profiles_node, 'billTo') bill_to_node = self.build_node_from_dict(bill_to_node, billing_info, BILL_TO_FIELDS) # credit_card payment_node = ET.SubElement(payment_profiles_node, 'payment') credit_card_info= to_camel_case(credit_card_info) if credit_card_info and (type(credit_card_info) is dict): credit_card_node = ET.SubElement(payment_node, 'creditCard') credit_card_node = self.build_node_from_dict(credit_card_node, credit_card_info, CREDIT_CARD_FIELDS) return payment_profiles_node
def get(self, **kwargs): """ Get the token to initiate a request for direct access to the Authorize.Net hosted profile page. Input fields: customer_profile_id hosted_profile_settings - optional setting_name setting_value Output fields: token - if not used within 15 minutes of the original API call, this token expires. """ if not self.customer_profile_id: msg_string = "%s Missing customer_profile_id in input." % \ 'getHostedProfilePageRequest' raise AttributeError(_(msg_string)) root_name = 'getHostedProfilePageRequest' xml_root = self.create_base_xml(root_name) customer_profile_id_node = ET.SubElement(xml_root, 'customerProfileId') customer_profile_id_node.text = self.customer_profile_id hosted_profile_settings = kwargs.get('hosted_profile_settings') if hosted_profile_settings and type(hosted_profile_settings) is dict: hosted_profile_settings_node = ET.SubElement( xml_root, 'hostedProfileSettings') hosted_profile_settings = to_camel_case(hosted_profile_settings) for key in hosted_profile_settings: setting_node = ET.SubElement(hosted_profile_settings_node, 'setting') hosted_profile_setting = {'settingName': key} setting_node = self.build_node_from_dict( setting_node, hosted_profile_setting, ('settingName', )) hosted_profile_setting = { 'settingValue': hosted_profile_settings[key] } setting_node = self.build_node_from_dict( setting_node, hosted_profile_setting, ('settingName', 'settingValue')) #print ET.tostring(xml_root) return self.process_request(xml_root)
def get(self, **kwargs): """ Get the token to initiate a request for direct access to the Authorize.Net hosted profile page. Input fields: customer_profile_id hosted_profile_settings - optional setting_name setting_value Output fields: token - if not used within 15 minutes of the original API call, this token expires. """ if not self.customer_profile_id: msg_string = "%s Missing customer_profile_id in input." % \ 'getHostedProfilePageRequest' raise AttributeError, _(msg_string) root_name = 'getHostedProfilePageRequest' xml_root = self.create_base_xml(root_name) customer_profile_id_node = ET.SubElement(xml_root, 'customerProfileId') customer_profile_id_node.text = self.customer_profile_id hosted_profile_settings = kwargs.get('hosted_profile_settings') if hosted_profile_settings and type(hosted_profile_settings) is dict: hosted_profile_settings_node = ET.SubElement(xml_root, 'hostedProfileSettings') hosted_profile_settings = to_camel_case(hosted_profile_settings) for key in hosted_profile_settings.keys(): setting_node = ET.SubElement(hosted_profile_settings_node, 'setting') hosted_profile_setting = {'settingName': key} setting_node = self.build_node_from_dict(setting_node, hosted_profile_setting, ('settingName', )) hosted_profile_setting = {'settingValue': hosted_profile_settings[key]} setting_node = self.build_node_from_dict(setting_node, hosted_profile_setting, ('settingName', 'settingValue')) #print ET.tostring(xml_root) return self.process_request(xml_root)
def create_transaction_node(self, **kwargs): amount = kwargs.get('amount', 0) if amount <= 0: msg_string = '%s - the amount %.2f is not greater than 0.' % \ ('<createCustomerProfileTransactionRequest', amount) raise ValueError(_(msg_string)) tax = kwargs.get('tax', '') shipping = kwargs.get('shipping') line_items_list = kwargs.get('line_items_list') customer_shipping_address_id = kwargs.get('customer_shipping_address_id') order = kwargs.get('order') tax_exempt = kwargs.get('tax_exempt') recurring_billing = kwargs.get('recurring_billing') card_code = kwargs.get('card_code') split_tender_id = kwargs.get('split_tender_id') transaction_node = ET.Element("transaction") trans_auth_capture_node = ET.SubElement(transaction_node, 'profileTransAuthCapture') # amount node amount_node = ET.SubElement(trans_auth_capture_node, "amount") amount_node.text = str(amount) # tax node if tax and type(tax) is dict: tax = to_camel_case(tax) tax_node = ET.SubElement(trans_auth_capture_node, 'tax') tax_node = self.build_node_from_dict(tax_node, tax, TAX_FIELDS) # tax node if shipping and type(shipping) is dict: shipping = to_camel_case(shipping) shipping_node = ET.SubElement(trans_auth_capture_node, 'shipping') shipping_node = self.build_node_from_dict(shipping_node, shipping, SHIPPING_FIELDS) # line items if line_items_list and type(line_items_list) is list: for line_items in line_items_list: if line_items and type(line_items) is dict: line_items_node = ET.SubElement(trans_auth_capture_node, 'lineItems') line_items_node = self.build_node_from_dict(line_items_node, line_items, LINE_ITEMS_FIELDS) # customer profile id customer_profile_id_node = ET.SubElement(trans_auth_capture_node, "customerProfileId") customer_profile_id_node.text = self.customer_profile_id # customer payment profile id customer_payment_profile_id_node = ET.SubElement(trans_auth_capture_node, "customerPaymentProfileId") customer_payment_profile_id_node.text = self.customer_payment_profile_id # customer shipping address id if customer_shipping_address_id: customer_shipping_address_id_node = ET.SubElement(trans_auth_capture_node, "customerShippingAddressId") customer_shipping_address_id_node.text = customer_shipping_address_id # order if order and type(order) is dict: order = to_camel_case(order) order_node = ET.SubElement(trans_auth_capture_node, 'order') order_node = self.build_node_from_dict(order_node, order, ORDER_FIELDS) # tax exempt if tax_exempt: tax_exempt_node = ET.SubElement(trans_auth_capture_node, "taxExempt") tax_exempt_node.text = tax_exempt # recurring billing if recurring_billing: recurring_billing_node = ET.SubElement(trans_auth_capture_node, "recurringBilling") recurring_billing_node.text = recurring_billing # card code if card_code: card_code_node = ET.SubElement(trans_auth_capture_node, "cardCode") card_code_node.text = card_code # split tender id if split_tender_id: split_tender_id_node = ET.SubElement(trans_auth_capture_node, "splitTenderId") split_tender_id_node.text = split_tender_id return transaction_node
def create_transaction_node(self, **kwargs): amount = kwargs.get('amount', 0) if amount <= 0: msg_string = '%s - the amount %.2f is not greater than 0.' % \ ('<createCustomerProfileTransactionRequest', amount) raise ValueError, _(msg_string) tax = kwargs.get('tax', '') shipping = kwargs.get('shipping') line_items_list = kwargs.get('line_items_list') customer_shipping_address_id = kwargs.get('customer_shipping_address_id') order = kwargs.get('order') tax_exempt = kwargs.get('tax_exempt') recurring_billing = kwargs.get('recurring_billing') card_code = kwargs.get('card_code') split_tender_id = kwargs.get('split_tender_id') transaction_node = ET.Element("transaction") trans_auth_capture_node = ET.SubElement(transaction_node, 'profileTransAuthCapture') # amount node amount_node = ET.SubElement(trans_auth_capture_node, "amount") amount_node.text = str(amount) # tax node if tax and type(tax) is dict: tax = to_camel_case(tax) tax_node = ET.SubElement(trans_auth_capture_node, 'tax') tax_node = self.build_node_from_dict(tax_node, tax, TAX_FIELDS) # tax node if shipping and type(shipping) is dict: shipping = to_camel_case(shipping) shipping_node = ET.SubElement(trans_auth_capture_node, 'shipping') shipping_node = self.build_node_from_dict(shipping_node, shipping, SHIPPING_FIELDS) # line items if line_items_list and type(line_items_list) is list: for line_items in line_items_list: if line_items and type(line_items) is dict: line_items_node = ET.SubElement(trans_auth_capture_node, 'lineItems') line_items_node = self.build_node_from_dict(line_items_node, line_items, LINE_ITEMS_FIELDS) # customer profile id customer_profile_id_node = ET.SubElement(trans_auth_capture_node, "customerProfileId") customer_profile_id_node.text = self.customer_profile_id # customer payment profile id customer_payment_profile_id_node = ET.SubElement(trans_auth_capture_node, "customerPaymentProfileId") customer_payment_profile_id_node.text = self.customer_payment_profile_id # customer shipping address id if customer_shipping_address_id: customer_shipping_address_id_node = ET.SubElement(trans_auth_capture_node, "customerShippingAddressId") customer_shipping_address_id_node.text = customer_shipping_address_id # order if order and type(order) is dict: order = to_camel_case(order) order_node = ET.SubElement(trans_auth_capture_node, 'order') order_node = self.build_node_from_dict(order_node, order, ORDER_FIELDS) # tax exempt if tax_exempt: tax_exempt_node = ET.SubElement(trans_auth_capture_node, "taxExempt") tax_exempt_node.text = tax_exempt # recurring billing if recurring_billing: recurring_billing_node = ET.SubElement(trans_auth_capture_node, "recurringBilling") recurring_billing_node.text = recurring_billing # card code if card_code: card_code_node = ET.SubElement(trans_auth_capture_node, "cardCode") card_code_node.text = card_code # split tender id if split_tender_id: split_tender_id_node = ET.SubElement(trans_auth_capture_node, "splitTenderId") split_tender_id_node.text = split_tender_id return transaction_node