Beispiel #1
0
 def test_validate_transaction_without_enums(self):
     try:
         Utils.validate_transaction(100, 'eur', 2, 1)
     except Exception:
         self.fail(
             'Utils.validate_transaction raised an exception unexpectedly when not using enums'
         )
Beispiel #2
0
 def test_validate_transaction_without_enums(self):
     try:
         Utils.validate_transaction(100, 'eur', 2)
     except errors.BadRequestError:
         self.fail(
             'Utils.validate_transaction raised BadRequestError unexpectedly when not using enums'
         )
Beispiel #3
0
 def test_validate_transaction(self):
     try:
         Utils.validate_transaction(100, sdk.Currency.USD,
                                    sdk.PaymentType.Recurring)
     except errors.BadRequestError:
         self.fail(
             'Utils.validate_transaction raised BadRequestError unexpectedly with enums'
         )
Beispiel #4
0
 def test_validate_transaction(self):
     try:
         Utils.validate_transaction(100, sdk.Currency.USD,
                                    sdk.PaymentType.Recurring,
                                    sdk.ChargeMode.NonThreeD)
     except Exception:
         self.fail(
             'Utils.validate_transaction raised an exception unexpectedly when using enums.'
         )
Beispiel #5
0
    def request_payment_token(
            self,
            # Transaction
            value=0,
            currency=sdk.default_currency,
            track_id=None,
            # Auto Capture
            auto_capture=sdk.default_auto_capture,
            auto_capture_delay=sdk.default_auto_capture_delay,
            # Urls
            success_url=None,
            fail_url=None,
            **kwargs):

        self._log_info('Payment token {}{} - {}'.format(
            value, currency, track_id if track_id else '<no track id>'))

        Utils.validate_transaction(value=value, currency=currency)

        request = {
            'value':
            value,
            'currency':
            currency
            if not isinstance(currency, sdk.Currency) else currency.value,
            'trackId':
            track_id,
            'chargeMode':
            sdk.ChargeMode.APM.value,  # pylint: disable = no-member
            'autoCapture':
            'Y' if auto_capture else 'N',
            'autoCapTime':
            auto_capture_delay,
            'successUrl':
            success_url,
            'failUrl':
            fail_url
        }

        # add remaining properties
        request.update(kwargs)

        http_response = self._send_http_request('tokens/payment',
                                                HttpMethod.POST, request)

        return PaymentTokenResponse(http_response)
Beispiel #6
0
    def _getPaymentActionResponse(self, id, action, value, track_id, **kwargs):
        self._log_info('{} - {} - {}'.format(
            action.capitalize(), id,
            track_id if track_id else '<no track id>'))

        Utils.validate_payment_id(id)

        request = {'trackId': track_id}

        if value is not None:
            Utils.validate_transaction(value=value)
            request['value'] = value

        # add remaining properties
        request.update(kwargs)

        return self._send_http_request('charges/{}/{}'.format(id, action),
                                       HttpMethod.POST, request)
Beispiel #7
0
    def request(self,
                card=None,
                token=None,
                value=0,
                currency=sdk.default_currency,
                payment_type=sdk.default_payment_type,
                customer=None,
                track_id=None,
                auto_capture=sdk.default_auto_capture,
                auto_capture_delay=sdk.default_auto_capture_delay,
                **kwargs):

        payment_source = card or token

        # card can be a dictionary and need the JSON case converted, if needed, before being validated
        if isinstance(card, dict):
            card = self._convert_json_case(card)
            # change payment source to a masked PAN
            payment_source = Utils.mask_pan(card['number'])

        self._log_info('Auth {} - {}{} - {}'.format(
            payment_source, value, currency,
            track_id if track_id else '<no track id>'))

        Utils.validate_payment_source(card=card, token=token)
        Utils.validate_transaction(value=value,
                                   currency=currency,
                                   payment_type=payment_type)
        Utils.validate_customer(customer=customer)

        request = {
            'value':
            value,
            'currency':
            currency
            if not isinstance(currency, sdk.Currency) else currency.value,
            'trackId':
            track_id,
            'transactionIndicator':
            payment_type if not isinstance(payment_type, sdk.PaymentType) else
            payment_type.value,
            'autoCapture':
            'Y' if auto_capture else 'N',
            'autoCapTime':
            auto_capture_delay
        }

        if card:
            if isinstance(card, dict):
                request['card'] = card
            else:
                request['cardId'] = card
        else:
            request['cardToken'] = token

        if Utils.is_id(customer):
            request['customerId'] = customer
        else:
            request['email'] = customer

        # add remaining properties
        request.update(kwargs)

        return PaymentProcessed(
            self._send_http_request(
                'charges/card' if card is not None else 'charges/token',
                HttpMethod.POST, request))
Beispiel #8
0
 def test_validate_transaction_fails_with_bad_payment_type(self):
     with self.assertRaises(errors.BadRequestError):
         Utils.validate_transaction(100, 'usd', 5)
Beispiel #9
0
 def test_validate_transaction_fails_with_bad_currency(self):
     with self.assertRaises(errors.BadRequestError):
         Utils.validate_transaction(100, 'xxx')
Beispiel #10
0
 def test_validate_transaction_fails_with_bad_value(self):
     with self.assertRaises(errors.BadRequestError):
         Utils.validate_transaction(-5)
Beispiel #11
0
 def test_validate_transaction_fails_with_wrong_value_type(self):
     with self.assertRaises(TypeError):
         Utils.validate_transaction('value')
Beispiel #12
0
 def test_validate_transaction_fails_with_negative_value(self):
     with self.assertRaises(ValueError):
         Utils.validate_transaction(-5)
Beispiel #13
0
 def test_validate_transaction_fails_with_missing_value(self):
     with self.assertRaises(ValueError):
         Utils.validate_transaction(None)
Beispiel #14
0
 def test_validate_transaction_fails_with_wrong_charge_mode_type(self):
     with self.assertRaises(TypeError):
         Utils.validate_transaction(100, 'usd', 2, False)
Beispiel #15
0
 def test_validate_transaction_fails_with_bad_charge_mode(self):
     with self.assertRaises(ValueError):
         Utils.validate_transaction(100, 'usd', 2, 10)
Beispiel #16
0
 def test_validate_transaction_fails_with_wrong_currency_type(self):
     with self.assertRaises(TypeError):
         Utils.validate_transaction(100, False)