示例#1
0
    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)
示例#2
0
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
示例#3
0
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