def from_dictionary(self, dictionary): super(PaymentProduct840SpecificOutput, self).from_dictionary(dictionary) if 'billingAddress' in dictionary: if not isinstance(dictionary['billingAddress'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['billingAddress'])) value = Address() self.billing_address = value.from_dictionary( dictionary['billingAddress']) if 'customerAccount' in dictionary: if not isinstance(dictionary['customerAccount'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['customerAccount'])) value = PaymentProduct840CustomerAccount() self.customer_account = value.from_dictionary( dictionary['customerAccount']) if 'customerAddress' in dictionary: if not isinstance(dictionary['customerAddress'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['customerAddress'])) value = Address() self.customer_address = value.from_dictionary( dictionary['customerAddress']) if 'protectionEligibility' in dictionary: if not isinstance(dictionary['protectionEligibility'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['protectionEligibility'])) value = ProtectionEligibility() self.protection_eligibility = value.from_dictionary( dictionary['protectionEligibility']) return self
def test_idempotence(self): """Test that the client can successfully detect that an idempotent request is sent twice""" amount_of_money = AmountOfMoney() amount_of_money.currency_code = "EUR" amount_of_money.amount = 100 billing_address = Address() billing_address.country_code = "BE" customer = Customer() customer.locale = "en" customer.billing_address = billing_address order = Order() order.amount_of_money = amount_of_money order.customer = customer card = Card() card.card_number = "4567350000427977" card.cardholder_name = "Wile E. Coyote" card.cvv = "123" card.expiry_date = "1234" payment_method_input = CardPaymentMethodSpecificInput() payment_method_input.return_url = "http://example.com" payment_method_input.payment_product_id = 1 payment_method_input.card = card body = CreatePaymentRequest() body.order = order body.card_payment_method_specific_input = payment_method_input idempotence_key = str(uuid.uuid4()) context = CallContext(idempotence_key) with init_utils.create_client() as client: response = client.merchant(MERCHANT_ID).payments().create_payment( body, context) payment_id = response.payment.id self.assertEqual(idempotence_key, context.idempotence_key) self.assertIsNone(context.idempotence_request_timestamp) response_2 = client.merchant( MERCHANT_ID).payments().create_payment(body, context) payment_id_2 = response_2.payment.id self.assertEqual(payment_id, payment_id_2) self.assertEqual(idempotence_key, context.idempotence_key) self.assertIsNotNone(context.idempotence_request_timestamp)
def create_request(): body = CreatePaymentRequest() order = Order() amount_of_money = AmountOfMoney() amount_of_money.amount = 2345 amount_of_money.currency_code = "CAD" customer = Customer() billing_address = Address() billing_address.county_code = "CA" customer.billing_address = billing_address order.customer = customer card_payment_method_specific_input = CardPaymentMethodSpecificInput() card_payment_method_specific_input.payment_product_id = 1 card = Card() card.cvv = "123" card.card_number = "4567350000427977" card.expiry_date = "1220" card_payment_method_specific_input.card = card body.card_payment_method_specific_input = card_payment_method_specific_input return body
def from_dictionary(self, dictionary): super(Customer, self).from_dictionary(dictionary) if 'account' in dictionary: if not isinstance(dictionary['account'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['account'])) value = CustomerAccount() self.account = value.from_dictionary(dictionary['account']) if 'accountType' in dictionary: self.account_type = dictionary['accountType'] if 'billingAddress' in dictionary: if not isinstance(dictionary['billingAddress'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['billingAddress'])) value = Address() self.billing_address = value.from_dictionary( dictionary['billingAddress']) if 'companyInformation' in dictionary: if not isinstance(dictionary['companyInformation'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['companyInformation'])) value = CompanyInformation() self.company_information = value.from_dictionary( dictionary['companyInformation']) if 'contactDetails' in dictionary: if not isinstance(dictionary['contactDetails'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['contactDetails'])) value = ContactDetails() self.contact_details = value.from_dictionary( dictionary['contactDetails']) if 'device' in dictionary: if not isinstance(dictionary['device'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['device'])) value = CustomerDevice() self.device = value.from_dictionary(dictionary['device']) if 'fiscalNumber' in dictionary: self.fiscal_number = dictionary['fiscalNumber'] if 'locale' in dictionary: self.locale = dictionary['locale'] if 'merchantCustomerId' in dictionary: self.merchant_customer_id = dictionary['merchantCustomerId'] if 'personalInformation' in dictionary: if not isinstance(dictionary['personalInformation'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['personalInformation'])) value = PersonalInformation() self.personal_information = value.from_dictionary( dictionary['personalInformation']) return self
def create_payment_request(): """Creates a commonly used payment for testing""" amount_of_money = AmountOfMoney() amount_of_money.currency_code = "CAD" amount_of_money.amount = 2345L billing_address = Address() billing_address.country_code = "CA" customer = Customer() customer.billing_address = billing_address order = Order() order.amount_of_money = amount_of_money order.customer = customer card = Card() card.cvv = "123" card.card_number = "1234567890123456" card.expiry_date = "1220" payment_specific_input = CardPaymentMethodSpecificInput() payment_specific_input.payment_product_id = 1 payment_specific_input.card = card request = CreatePaymentRequest() request.order = order request.card_payment_method_specific_input = payment_specific_input return request
def from_dictionary(self, dictionary): super(CustomerToken, self).from_dictionary(dictionary) if 'billingAddress' in dictionary: if not isinstance(dictionary['billingAddress'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['billingAddress'])) value = Address() self.billing_address = value.from_dictionary(dictionary['billingAddress']) if 'companyInformation' in dictionary: if not isinstance(dictionary['companyInformation'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['companyInformation'])) value = CompanyInformation() self.company_information = value.from_dictionary(dictionary['companyInformation']) if 'personalInformation' in dictionary: if not isinstance(dictionary['personalInformation'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['personalInformation'])) value = PersonalInformationToken() self.personal_information = value.from_dictionary(dictionary['personalInformation']) return self