예제 #1
0
 def test_validate_payment_source_token(self):
     try:
         Utils.validate_payment_source(None, self.TOKEN_ID)
     except errors.BadRequestError:
         self.fail(
             'Utils.validate_payment_source raised BadRequestError unexpectedly for a valid token'
         )
예제 #2
0
 def test_validate_payment_source_card(self):
     try:
         Utils.validate_payment_source(self.CARD_ID)
     except errors.BadRequestError:
         self.fail(
             'Utils.validate_payment_source raised BadRequestError unexpectedly for a valid card id'
         )
예제 #3
0
 def test_validate_payment_source_token(self):
     try:
         Utils.validate_payment_source(None, self.VALID_ID)
     except Exception:
         self.fail(
             'Utils.validate_payment_source raised an exception unexpectedly for a valid token.'
         )
예제 #4
0
 def test_validate_payment_source_card(self):
     try:
         Utils.validate_payment_source(self.VALID_ID)
     except Exception:
         self.fail(
             'Utils.validate_payment_source raised an exception unexpectedly for a valid card source.'
         )
예제 #5
0
 def test_validate_payment_source_full_card_fails(self):
     with self.assertRaises(errors.BadRequestError):
         Utils.validate_payment_source({
             'number': '4242424242424241',
             'expiryMonth': 6,
             'expiryYear': 2025,
             'cvv': '100'
         })
예제 #6
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))
예제 #7
0
 def test_validate_payment_source_token_fails(self):
     with self.assertRaises(errors.BadRequestError):
         Utils.validate_payment_source(None, self.INVALID_ID)
예제 #8
0
 def test_validate_payment_source_fails(self):
     with self.assertRaises(errors.BadRequestError):
         Utils.validate_payment_source(None, None)
예제 #9
0
 def test_validate_payment_source_card_id_fails(self):
     with self.assertRaises(TypeError):
         Utils.validate_payment_source(self.INVALID_ID)
예제 #10
0
 def test_validate_payment_source_with_missing_source(self):
     with self.assertRaises(ValueError):
         Utils.validate_payment_source(None, None)