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 from_dictionary(self, dictionary): super(CreatePaymentRequest, self).from_dictionary(dictionary) if 'cardPaymentMethodSpecificInput' in dictionary: if not isinstance(dictionary['cardPaymentMethodSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['cardPaymentMethodSpecificInput'])) value = CardPaymentMethodSpecificInput() self.card_payment_method_specific_input = value.from_dictionary( dictionary['cardPaymentMethodSpecificInput']) if 'encryptedCustomerInput' in dictionary: self.encrypted_customer_input = dictionary[ 'encryptedCustomerInput'] if 'fraudFields' in dictionary: if not isinstance(dictionary['fraudFields'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['fraudFields'])) value = FraudFields() self.fraud_fields = value.from_dictionary( dictionary['fraudFields']) if 'hostedTokenizationId' in dictionary: self.hosted_tokenization_id = dictionary['hostedTokenizationId'] if 'mobilePaymentMethodSpecificInput' in dictionary: if not isinstance(dictionary['mobilePaymentMethodSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['mobilePaymentMethodSpecificInput'])) value = MobilePaymentMethodSpecificInput() self.mobile_payment_method_specific_input = value.from_dictionary( dictionary['mobilePaymentMethodSpecificInput']) if 'order' in dictionary: if not isinstance(dictionary['order'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['order'])) value = Order() self.order = value.from_dictionary(dictionary['order']) if 'redirectPaymentMethodSpecificInput' in dictionary: if not isinstance(dictionary['redirectPaymentMethodSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['redirectPaymentMethodSpecificInput'])) value = RedirectPaymentMethodSpecificInput() self.redirect_payment_method_specific_input = value.from_dictionary( dictionary['redirectPaymentMethodSpecificInput']) if 'sepaDirectDebitPaymentMethodSpecificInput' in dictionary: if not isinstance( dictionary['sepaDirectDebitPaymentMethodSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['sepaDirectDebitPaymentMethodSpecificInput'])) value = SepaDirectDebitPaymentMethodSpecificInput() self.sepa_direct_debit_payment_method_specific_input = value.from_dictionary( dictionary['sepaDirectDebitPaymentMethodSpecificInput']) return self
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 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(CompletePaymentRequest, self).from_dictionary(dictionary) if 'cardPaymentMethodSpecificInput' in dictionary: if not isinstance(dictionary['cardPaymentMethodSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['cardPaymentMethodSpecificInput'])) value = CompletePaymentCardPaymentMethodSpecificInput() self.card_payment_method_specific_input = value.from_dictionary( dictionary['cardPaymentMethodSpecificInput']) if 'order' in dictionary: if not isinstance(dictionary['order'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['order'])) value = Order() self.order = value.from_dictionary(dictionary['order']) return self
def from_dictionary(self, dictionary): super(CreateHostedCheckoutRequest, self).from_dictionary(dictionary) if 'cardPaymentMethodSpecificInput' in dictionary: if not isinstance(dictionary['cardPaymentMethodSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['cardPaymentMethodSpecificInput'])) value = CardPaymentMethodSpecificInputBase() self.card_payment_method_specific_input = value.from_dictionary(dictionary['cardPaymentMethodSpecificInput']) if 'fraudFields' in dictionary: if not isinstance(dictionary['fraudFields'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['fraudFields'])) value = FraudFields() self.fraud_fields = value.from_dictionary(dictionary['fraudFields']) if 'hostedCheckoutSpecificInput' in dictionary: if not isinstance(dictionary['hostedCheckoutSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['hostedCheckoutSpecificInput'])) value = HostedCheckoutSpecificInput() self.hosted_checkout_specific_input = value.from_dictionary(dictionary['hostedCheckoutSpecificInput']) if 'mobilePaymentMethodSpecificInput' in dictionary: if not isinstance(dictionary['mobilePaymentMethodSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['mobilePaymentMethodSpecificInput'])) value = MobilePaymentMethodHostedCheckoutSpecificInput() self.mobile_payment_method_specific_input = value.from_dictionary(dictionary['mobilePaymentMethodSpecificInput']) if 'order' in dictionary: if not isinstance(dictionary['order'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['order'])) value = Order() self.order = value.from_dictionary(dictionary['order']) if 'redirectPaymentMethodSpecificInput' in dictionary: if not isinstance(dictionary['redirectPaymentMethodSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['redirectPaymentMethodSpecificInput'])) value = RedirectPaymentMethodSpecificInput() self.redirect_payment_method_specific_input = value.from_dictionary(dictionary['redirectPaymentMethodSpecificInput']) if 'sepaDirectDebitPaymentMethodSpecificInput' in dictionary: if not isinstance(dictionary['sepaDirectDebitPaymentMethodSpecificInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['sepaDirectDebitPaymentMethodSpecificInput'])) value = SepaDirectDebitPaymentMethodSpecificInputBase() self.sepa_direct_debit_payment_method_specific_input = value.from_dictionary(dictionary['sepaDirectDebitPaymentMethodSpecificInput']) return self