def alternative_payment_request(self, apm_id, payment_token, user_data=None, customer=None, **kwargs): Utils.validate_ap_transaction( apm_id=apm_id, payment_token=payment_token, user_data=user_data) Utils.validate_customer(customer=customer) request = { 'localPayment': { 'lppId': apm_id if not isinstance(apm_id, sdk.AlternativePaymentMethodId) else apm_id.value, 'userData': user_data }, 'paymentToken': payment_token } if Utils.is_email(customer): request['email'] = customer else: request['customerId'] = customer request.update(kwargs) return AlternativePaymentResponse( self._send_http_request('charges/localpayment', HttpMethod.POST, request))
def test_validate_customer(self): try: Utils.validate_customer(self.CUSTOMER_ID) Utils.validate_customer(self.EMAIL) except errors.BadRequestError: self.fail( 'Utils.validate_customer raised BadRequestError unexpectedly for a valid customer id' )
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_validate_customer_fails(self): with self.assertRaises(errors.BadRequestError): Utils.validate_customer(self.INVALID_ID)
def test_validate_customer_with_wrong_id_type(self): with self.assertRaises(TypeError): Utils.validate_customer(self.INVALID_ID)
def test_validate_customer_with_missing_id(self): with self.assertRaises(ValueError): Utils.validate_customer(None)