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 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(Order, self).from_dictionary(dictionary) if 'additionalInput' in dictionary: if not isinstance(dictionary['additionalInput'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['additionalInput'])) value = AdditionalOrderInput() self.additional_input = value.from_dictionary( dictionary['additionalInput']) if 'amountOfMoney' in dictionary: if not isinstance(dictionary['amountOfMoney'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['amountOfMoney'])) value = AmountOfMoney() self.amount_of_money = value.from_dictionary( dictionary['amountOfMoney']) if 'customer' in dictionary: if not isinstance(dictionary['customer'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['customer'])) value = Customer() self.customer = value.from_dictionary(dictionary['customer']) if 'references' in dictionary: if not isinstance(dictionary['references'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['references'])) value = OrderReferences() self.references = value.from_dictionary(dictionary['references']) if 'shipping' in dictionary: if not isinstance(dictionary['shipping'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['shipping'])) value = Shipping() self.shipping = value.from_dictionary(dictionary['shipping']) if 'shoppingCart' in dictionary: if not isinstance(dictionary['shoppingCart'], dict): raise TypeError('value \'{}\' is not a dictionary'.format( dictionary['shoppingCart'])) value = ShoppingCart() self.shopping_cart = value.from_dictionary( dictionary['shoppingCart']) return self