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 request(self, # Source card=None, token=None, # Transaction value=0, currency=sdk.default_currency, payment_type=sdk.default_payment_type, customer=None, track_id=None, # Auto Capture auto_capture=sdk.default_auto_capture, auto_capture_delay=sdk.default_auto_capture_delay, # 3D charge_mode=sdk.ChargeMode.NonThreeD, attempt_n3d=False, **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, charge_mode=charge_mode) 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, 'chargeMode': charge_mode if not isinstance(charge_mode, sdk.ChargeMode) else charge_mode.value, 'attemptN3D': attempt_n3d, '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_email(customer): request['email'] = customer else: request['customerId'] = customer # add remaining properties request.update(kwargs) http_response = self._send_http_request('charges/card' if card is not None else 'charges/token', HttpMethod.POST, request) if Utils.verify_redirect_flow(http_response): return ThreeDSResponse(http_response) else: return PaymentProcessed(http_response)