internal static GpApiRequest BuildRequest(Secure3dBuilder builder, GpApiConnector gateway) { var merchantUrl = !string.IsNullOrEmpty(gateway.GpApiConfig.MerchantId) ? $"/merchants/{gateway.GpApiConfig.MerchantId}" : string.Empty; if (builder.TransactionType == TransactionType.VerifyEnrolled) { var storedCredential = new JsonDoc() .Set("model", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential?.Type)) .Set("reason", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential?.Reason)) .Set("sequence", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential?.Sequence)); var paymentMethod = new JsonDoc(); if (builder.PaymentMethod is ITokenizable tokenized && !string.IsNullOrEmpty(tokenized.Token)) { paymentMethod.Set("id", tokenized.Token); } else if (builder.PaymentMethod is ICardData cardData) { var card = new JsonDoc() .Set("number", cardData.Number) .Set("expiry_month", cardData.ExpMonth?.ToString().PadLeft(2, '0')) .Set("expiry_year", cardData.ExpYear?.ToString().PadLeft(4, '0').Substring(2, 2)); paymentMethod.Set("card", card); } var notifications = new JsonDoc() .Set("challenge_return_url", gateway.GpApiConfig.ChallengeNotificationUrl) .Set("three_ds_method_return_url", gateway.GpApiConfig.MethodNotificationUrl); var data = new JsonDoc() .Set("account_name", gateway.GpApiConfig.AccessTokenInfo.TransactionProcessingAccountName) .Set("reference", builder.ReferenceNumber ?? Guid.NewGuid().ToString()) .Set("channel", EnumConverter.GetMapping(Target.GP_API, gateway.GpApiConfig.Channel)) .Set("amount", builder.Amount.ToNumericCurrencyString()) .Set("currency", builder.Currency) .Set("country", gateway.GpApiConfig.Country) .Set("preference", builder.ChallengeRequestIndicator?.ToString()) .Set("source", builder.AuthenticationSource.ToString()) .Set("initator", EnumConverter.GetMapping(Target.GP_API, builder.StoredCredential?.Initiator)) .Set("stored_credential", storedCredential.HasKeys() ? storedCredential : null) .Set("payment_method", paymentMethod) .Set("notifications", notifications.HasKeys() ? notifications : null); return(new GpApiRequest { Verb = HttpMethod.Post, Endpoint = $"{merchantUrl}/authentications", RequestBody = data.ToString(), }); }
public Transaction ProcessOpenBanking(BankPaymentBuilder builder) { string timestamp = builder.Timestamp ?? GenerationUtils.GenerateTimestamp(); string orderId = builder.OrderId ?? GenerationUtils.GenerateOrderId(); var amount = builder.Amount != null?builder.Amount.ToNumericCurrencyString() : null; JsonDoc request = new JsonDoc(); var paymentMethod = builder.PaymentMethod as BankPayment; switch (builder.TransactionType) { case TransactionType.Sale: var bankPaymentType = paymentMethod.BankPaymentType != null ? paymentMethod.BankPaymentType : GetBankPaymentType(builder.Currency); string hash = GenerationUtils.GenerateHash(SharedSecret, ShaHashType, timestamp, MerchantId, orderId, amount, builder.Currency, !string.IsNullOrEmpty(paymentMethod.SortCode) && bankPaymentType.Equals(BankPaymentType.FASTERPAYMENTS) ? paymentMethod.SortCode : "", !string.IsNullOrEmpty(paymentMethod.AccountNumber) && bankPaymentType.Equals(BankPaymentType.FASTERPAYMENTS) ? paymentMethod.AccountNumber : "", !string.IsNullOrEmpty(paymentMethod.Iban) && bankPaymentType.Equals(BankPaymentType.SEPA) ? paymentMethod.Iban : ""); SetAuthorizationHeader(hash); request.Set("request_timestamp", timestamp) .Set("merchant_id", MerchantId) .Set("account_id", AccountId); JsonDoc order = new JsonDoc(); order.Set("id", orderId) .Set("currency", builder.Currency) .Set("amount", amount) .Set("description", builder.Description); JsonDoc payment = new JsonDoc(); JsonDoc destination = new JsonDoc(); destination.Set("account_number", bankPaymentType.Equals(BankPaymentType.FASTERPAYMENTS) ? paymentMethod.AccountNumber : null) .Set("sort_code", bankPaymentType.Equals(BankPaymentType.FASTERPAYMENTS) ? paymentMethod.SortCode : null) .Set("iban", bankPaymentType.Equals(BankPaymentType.SEPA) ? paymentMethod.Iban : null) .Set("name", paymentMethod.AccountName); JsonDoc remittance_reference = new JsonDoc(); remittance_reference.Set("type", builder.RemittanceReferenceType != null ? builder.RemittanceReferenceType.ToString() : null) .Set("value", builder.RemittanceReferenceValue); payment.Set("scheme", bankPaymentType.ToString()) .Set("destination", destination); if (remittance_reference.HasKeys()) { payment.Set("remittance_reference", remittance_reference); } request.Set("order", order) .Set("payment", payment) .Set("return_url", paymentMethod.ReturnUrl) .Set("status_url", paymentMethod.StatusUpdateUrl); break; default: break; } try { string rawResponse = DoTransaction(HttpMethod.Post, "/payments", request.ToString()); return(OpenBankingMapping.MapResponse(rawResponse)); } catch (GatewayException gatewayException) { throw gatewayException; } }