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))
def test_mask_pan(self): self.assertEqual(Utils.mask_pan(self.VALID_PAN), '424242******4242')