Example #1
0
 def from_dictionary(self, dictionary):
     super(CancelPaymentRequest, self).from_dictionary(dictionary)
     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 'isFinal' in dictionary:
         self.is_final = dictionary['isFinal']
     return self
Example #2
0
 def from_dictionary(self, dictionary):
     super(PayoutOutput, self).from_dictionary(dictionary)
     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'])
     return self
Example #3
0
 def from_dictionary(self, dictionary):
     super(GiftCardPurchase, self).from_dictionary(dictionary)
     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 'numberOfGiftCards' in dictionary:
         self.number_of_gift_cards = dictionary['numberOfGiftCards']
     return self
Example #4
0
 def from_dictionary(self, dictionary):
     super(PaymentContext, self).from_dictionary(dictionary)
     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 'countryCode' in dictionary:
         self.country_code = dictionary['countryCode']
     if 'isRecurring' in dictionary:
         self.is_recurring = dictionary['isRecurring']
     return self
Example #5
0
 def from_dictionary(self, dictionary):
     super(RefundRequest, self).from_dictionary(dictionary)
     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 'references' in dictionary:
         if not isinstance(dictionary['references'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['references']))
         value = PaymentReferences()
         self.references = value.from_dictionary(dictionary['references'])
     return self
Example #6
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)
Example #7
0
 def from_dictionary(self, dictionary):
     super(OperationOutput, self).from_dictionary(dictionary)
     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 'id' in dictionary:
         self.id = dictionary['id']
     if 'paymentMethod' in dictionary:
         self.payment_method = dictionary['paymentMethod']
     if 'references' in dictionary:
         if not isinstance(dictionary['references'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['references']))
         value = PaymentReferences()
         self.references = value.from_dictionary(dictionary['references'])
     if 'status' in dictionary:
         self.status = dictionary['status']
     if 'statusOutput' in dictionary:
         if not isinstance(dictionary['statusOutput'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['statusOutput']))
         value = PaymentStatusOutput()
         self.status_output = value.from_dictionary(
             dictionary['statusOutput'])
     return self
Example #8
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
Example #9
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
Example #10
0
 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
Example #11
0
 def from_dictionary(self, dictionary):
     super(CreatePayoutRequest, self).from_dictionary(dictionary)
     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 'cardPayoutMethodSpecificInput' in dictionary:
         if not isinstance(dictionary['cardPayoutMethodSpecificInput'],
                           dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['cardPayoutMethodSpecificInput']))
         value = CardPayoutMethodSpecificInput()
         self.card_payout_method_specific_input = value.from_dictionary(
             dictionary['cardPayoutMethodSpecificInput'])
     if 'references' in dictionary:
         if not isinstance(dictionary['references'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['references']))
         value = PaymentReferences()
         self.references = value.from_dictionary(dictionary['references'])
     return self
Example #12
0
 def from_dictionary(self, dictionary):
     super(LineItem, self).from_dictionary(dictionary)
     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 'invoiceData' in dictionary:
         if not isinstance(dictionary['invoiceData'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['invoiceData']))
         value = LineItemInvoiceData()
         self.invoice_data = value.from_dictionary(
             dictionary['invoiceData'])
     if 'orderLineDetails' in dictionary:
         if not isinstance(dictionary['orderLineDetails'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['orderLineDetails']))
         value = OrderLineDetails()
         self.order_line_details = value.from_dictionary(
             dictionary['orderLineDetails'])
     return self
Example #13
0
 def from_dictionary(self, dictionary):
     super(RefundOutput, self).from_dictionary(dictionary)
     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 'amountPaid' in dictionary:
         self.amount_paid = dictionary['amountPaid']
     if 'cardRefundMethodSpecificOutput' in dictionary:
         if not isinstance(dictionary['cardRefundMethodSpecificOutput'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['cardRefundMethodSpecificOutput']))
         value = RefundCardMethodSpecificOutput()
         self.card_refund_method_specific_output = value.from_dictionary(dictionary['cardRefundMethodSpecificOutput'])
     if 'eWalletRefundMethodSpecificOutput' in dictionary:
         if not isinstance(dictionary['eWalletRefundMethodSpecificOutput'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['eWalletRefundMethodSpecificOutput']))
         value = RefundEWalletMethodSpecificOutput()
         self.e_wallet_refund_method_specific_output = value.from_dictionary(dictionary['eWalletRefundMethodSpecificOutput'])
     if 'merchantParameters' in dictionary:
         self.merchant_parameters = dictionary['merchantParameters']
     if 'mobileRefundMethodSpecificOutput' in dictionary:
         if not isinstance(dictionary['mobileRefundMethodSpecificOutput'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['mobileRefundMethodSpecificOutput']))
         value = RefundMobileMethodSpecificOutput()
         self.mobile_refund_method_specific_output = value.from_dictionary(dictionary['mobileRefundMethodSpecificOutput'])
     if 'paymentMethod' in dictionary:
         self.payment_method = dictionary['paymentMethod']
     if 'redirectRefundMethodSpecificOutput' in dictionary:
         if not isinstance(dictionary['redirectRefundMethodSpecificOutput'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['redirectRefundMethodSpecificOutput']))
         value = RefundRedirectMethodSpecificOutput()
         self.redirect_refund_method_specific_output = value.from_dictionary(dictionary['redirectRefundMethodSpecificOutput'])
     if 'references' in dictionary:
         if not isinstance(dictionary['references'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(dictionary['references']))
         value = PaymentReferences()
         self.references = value.from_dictionary(dictionary['references'])
     return self
Example #14
0
 def from_dictionary(self, dictionary):
     super(PaymentOutput, self).from_dictionary(dictionary)
     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 'amountPaid' in dictionary:
         self.amount_paid = dictionary['amountPaid']
     if 'cardPaymentMethodSpecificOutput' in dictionary:
         if not isinstance(dictionary['cardPaymentMethodSpecificOutput'],
                           dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['cardPaymentMethodSpecificOutput']))
         value = CardPaymentMethodSpecificOutput()
         self.card_payment_method_specific_output = value.from_dictionary(
             dictionary['cardPaymentMethodSpecificOutput'])
     if 'customer' in dictionary:
         if not isinstance(dictionary['customer'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['customer']))
         value = CustomerOutput()
         self.customer = value.from_dictionary(dictionary['customer'])
     if 'merchantParameters' in dictionary:
         self.merchant_parameters = dictionary['merchantParameters']
     if 'mobilePaymentMethodSpecificOutput' in dictionary:
         if not isinstance(dictionary['mobilePaymentMethodSpecificOutput'],
                           dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['mobilePaymentMethodSpecificOutput']))
         value = MobilePaymentMethodSpecificOutput()
         self.mobile_payment_method_specific_output = value.from_dictionary(
             dictionary['mobilePaymentMethodSpecificOutput'])
     if 'paymentMethod' in dictionary:
         self.payment_method = dictionary['paymentMethod']
     if 'redirectPaymentMethodSpecificOutput' in dictionary:
         if not isinstance(
                 dictionary['redirectPaymentMethodSpecificOutput'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['redirectPaymentMethodSpecificOutput']))
         value = RedirectPaymentMethodSpecificOutput()
         self.redirect_payment_method_specific_output = value.from_dictionary(
             dictionary['redirectPaymentMethodSpecificOutput'])
     if 'references' in dictionary:
         if not isinstance(dictionary['references'], dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['references']))
         value = PaymentReferences()
         self.references = value.from_dictionary(dictionary['references'])
     if 'sepaDirectDebitPaymentMethodSpecificOutput' in dictionary:
         if not isinstance(
                 dictionary['sepaDirectDebitPaymentMethodSpecificOutput'],
                 dict):
             raise TypeError('value \'{}\' is not a dictionary'.format(
                 dictionary['sepaDirectDebitPaymentMethodSpecificOutput']))
         value = SepaDirectDebitPaymentMethodSpecificOutput()
         self.sepa_direct_debit_payment_method_specific_output = value.from_dictionary(
             dictionary['sepaDirectDebitPaymentMethodSpecificOutput'])
     return self