# Path: tests/integration/init_utils.py
# MERCHANT_ID = str(os.getenv("connect.api.merchantId"))
# 
# Path: ingenico/connect/sdk/domain/definitions/amount_of_money.py
# class AmountOfMoney(DataObject):
# 
#     __amount = None
#     __currency_code = None
# 
#     @property
#     def amount(self):
#         """
#         | Amount in cents and always having 2 decimals
#         
#         Type: int
#         """
#         return self.__amount
# 
#     @amount.setter
#     def amount(self, value):
#         self.__amount = value
# 
#     @property
#     def currency_code(self):
#         """
#         | Three-letter ISO currency code representing the currency for the amount
#         
#         Type: str
#         """
#         return self.__currency_code
# 
#     @currency_code.setter
#     def currency_code(self, value):
#         self.__currency_code = value
# 
#     def to_dictionary(self):
#         dictionary = super(AmountOfMoney, self).to_dictionary()
#         if self.amount is not None:
#             dictionary['amount'] = self.amount
#         if self.currency_code is not None:
#             dictionary['currencyCode'] = self.currency_code
#         return dictionary
# 
#     def from_dictionary(self, dictionary):
#         super(AmountOfMoney, self).from_dictionary(dictionary)
#         if 'amount' in dictionary:
#             self.amount = dictionary['amount']
#         if 'currencyCode' in dictionary:
#             self.currency_code = dictionary['currencyCode']
#         return self
# 
# Path: ingenico/connect/sdk/declined_payment_exception.py
# class DeclinedPaymentException(DeclinedTransactionException):
#     """
#     Represents an error response from a create payment call.
#     """
# 
#     def __init__(self, status_code, response_body, errors):
#         if errors is not None:
#             super(DeclinedPaymentException, self).__init__(status_code,
#                                                            response_body,
#                                                            errors.error_id,
#                                                            errors.errors,
#                                                            DeclinedPaymentException.__create_message(
#                                                                errors))
#         else:
#             super(DeclinedPaymentException, self).__init__(status_code,
#                                                            response_body,
#                                                            None, None,
#                                                            DeclinedPaymentException.__create_message())
#         self.__errors = errors
# 
#     @staticmethod
#     def __create_message(errors=None):
#         if errors is not None and errors.payment_result is not None:
#             payment = errors.payment_result.payment
#         else:
#             payment = None
#         if payment is not None:
#             return "declined payment '" + payment.id + "' with status '" + payment.status + "'"
#         else:
#             return "the Ingenico ePayments platform returned a declined payment response"
# 
#     @property
#     def create_payment_result(self):
#         """
#         :return: The result of creating a payment if available, otherwise None.
#         """
#         if self.__errors is None:
#             return None
#         else:
#             return self.__errors.payment_result


import unittest
import uuid
import tests.integration.init_utils as init_utils
from tests.integration.init_utils import MERCHANT_ID
from ingenico.connect.sdk.domain.definitions.address import Address
from ingenico.connect.sdk.domain.definitions.amount_of_money import AmountOfMoney
from ingenico.connect.sdk.domain.payment.create_payment_request import CreatePaymentRequest
from ingenico.connect.sdk.domain.payment.definitions.customer import Customer
from ingenico.connect.sdk.domain.payment.definitions.order import Order
from ingenico.connect.sdk.domain.payment.definitions.redirect_payment_method_specific_input import \
    RedirectPaymentMethodSpecificInput
from ingenico.connect.sdk.domain.payment.definitions.redirect_payment_product809_specific_input import \
    RedirectPaymentProduct809SpecificInput
from ingenico.connect.sdk.call_context import CallContext
from ingenico.connect.sdk.declined_payment_exception import DeclinedPaymentException

        amount_of_money = AmountOfMoney()
        amount_of_money.currency_code = "EUR"
        amount_of_money.amount = 100
        billing_address = Address()
        billing_address.country_code = "NL"
        customer = Customer()
        customer.locale = "en"
        customer.billing_address = billing_address
        order = Order()
        order.amount_of_money = amount_of_money
        order.customer = customer
        payment_product_input = RedirectPaymentProduct809SpecificInput()
        payment_product_input.issuer_id = "INGBNL2A"
        payment_method_input = RedirectPaymentMethodSpecificInput()
        payment_method_input.return_url = "http://example.com"
        payment_method_input.payment_product_id = 809
        payment_method_input.payment_product809_specific_input = payment_product_input
        body = CreatePaymentRequest()
        body.order = order
        body.redirect_payment_method_specific_input = payment_method_input
        idempotence_key = str(uuid.uuid4())
        context = CallContext(idempotence_key)

        with init_utils.create_client() as client:
            def do_create_payment():
                # For this test it doesn't matter if the response is successful or declined,
                # as long as idempotence is handled correctly
                try:
                    return client.merchant(MERCHANT_ID).payments().create(body, context)

# Path: tests/integration/init_utils.py
# MERCHANT_ID = str(os.getenv("connect.api.merchantId"))
# 
# Path: ingenico/connect/sdk/domain/definitions/amount_of_money.py
# class AmountOfMoney(DataObject):
# 
#     __amount = None
#     __currency_code = None
# 
#     @property
#     def amount(self):
#         """
#         | Amount in cents and always having 2 decimals
#         
#         Type: int
#         """
#         return self.__amount
# 
#     @amount.setter
#     def amount(self, value):
#         self.__amount = value
# 
#     @property
#     def currency_code(self):
#         """
#         | Three-letter ISO currency code representing the currency for the amount
#         
#         Type: str
#         """
#         return self.__currency_code
# 
#     @currency_code.setter
#     def currency_code(self, value):
#         self.__currency_code = value
# 
#     def to_dictionary(self):
#         dictionary = super(AmountOfMoney, self).to_dictionary()
#         if self.amount is not None:
#             dictionary['amount'] = self.amount
#         if self.currency_code is not None:
#             dictionary['currencyCode'] = self.currency_code
#         return dictionary
# 
#     def from_dictionary(self, dictionary):
#         super(AmountOfMoney, self).from_dictionary(dictionary)
#         if 'amount' in dictionary:
#             self.amount = dictionary['amount']
#         if 'currencyCode' in dictionary:
#             self.currency_code = dictionary['currencyCode']
#         return self
# 
# Path: ingenico/connect/sdk/declined_payment_exception.py
# class DeclinedPaymentException(DeclinedTransactionException):
#     """
#     Represents an error response from a create payment call.
#     """
# 
#     def __init__(self, status_code, response_body, errors):
#         if errors is not None:
#             super(DeclinedPaymentException, self).__init__(status_code,
#                                                            response_body,
#                                                            errors.error_id,
#                                                            errors.errors,
#                                                            DeclinedPaymentException.__create_message(
#                                                                errors))
#         else:
#             super(DeclinedPaymentException, self).__init__(status_code,
#                                                            response_body,
#                                                            None, None,
#                                                            DeclinedPaymentException.__create_message())
#         self.__errors = errors
# 
#     @staticmethod
#     def __create_message(errors=None):
#         if errors is not None and errors.payment_result is not None:
#             payment = errors.payment_result.payment
#         else:
#             payment = None
#         if payment is not None:
#             return "declined payment '" + payment.id + "' with status '" + payment.status + "'"
#         else:
#             return "the Ingenico ePayments platform returned a declined payment response"
# 
#     @property
#     def create_payment_result(self):
#         """
#         :return: The result of creating a payment if available, otherwise None.
#         """
#         if self.__errors is None:
#             return None
#         else:
#             return self.__errors.payment_result


# Path: tests/integration/test_idempotence.py
import unittest
import uuid
import tests.integration.init_utils as init_utils
from tests.integration.init_utils import MERCHANT_ID
from ingenico.connect.sdk.domain.definitions.address import Address
from ingenico.connect.sdk.domain.definitions.amount_of_money import AmountOfMoney
from ingenico.connect.sdk.domain.payment.create_payment_request import CreatePaymentRequest
from ingenico.connect.sdk.domain.payment.definitions.customer import Customer
from ingenico.connect.sdk.domain.payment.definitions.order import Order
from ingenico.connect.sdk.domain.payment.definitions.redirect_payment_method_specific_input import \
    RedirectPaymentMethodSpecificInput
from ingenico.connect.sdk.domain.payment.definitions.redirect_payment_product809_specific_input import \
    RedirectPaymentProduct809SpecificInput
from ingenico.connect.sdk.call_context import CallContext
from ingenico.connect.sdk.declined_payment_exception import DeclinedPaymentException


        amount_of_money = AmountOfMoney()
        amount_of_money.currency_code = "EUR"
        amount_of_money.amount = 100
        billing_address = Address()
        billing_address.country_code = "NL"
        customer = Customer()
        customer.locale = "en"
        customer.billing_address = billing_address
        order = Order()
        order.amount_of_money = amount_of_money
        order.customer = customer
        payment_product_input = RedirectPaymentProduct809SpecificInput()
        payment_product_input.issuer_id = "INGBNL2A"
        payment_method_input = RedirectPaymentMethodSpecificInput()
        payment_method_input.return_url = "http://example.com"
        payment_method_input.payment_product_id = 809
        payment_method_input.payment_product809_specific_input = payment_product_input
        body = CreatePaymentRequest()
        body.order = order
        body.redirect_payment_method_specific_input = payment_method_input
        idempotence_key = str(uuid.uuid4())
        context = CallContext(idempotence_key)

        with init_utils.create_client() as client:
            def do_create_payment():
                # For this test it doesn't matter if the response is successful or declined,
                # as long as idempotence is handled correctly
                try:
                    return client.merchant(MERCHANT_ID).payments().create(body, context)

                except DeclinedPaymentException as e: