public override int ThreeDSecurePayment(Payment payment, Uri postBackURL, string languageCode = "", string languageDialectCode = "") { int ret = 10; string url = ""; err = ""; try { StripeConfiguration.ApiKey = payment.ProviderPassword; // Secret key if (postBackURL == null) { url = Tools.ConfigValue("SystemURL"); } else { url = postBackURL.GetLeftPart(UriPartial.Authority); } if (!url.EndsWith("/")) { url = url + "/"; } d3Form = ""; ret = 20; url = url + "RegisterThreeD.aspx?ProviderCode=" + bureauCode + "&TransRef=" + Tools.XMLSafe(payment.MerchantReference); ret = 50; var paymentMethodOptions = new PaymentMethodCreateOptions { Type = "card", Card = new PaymentMethodCardOptions { Number = payment.CardNumber, ExpMonth = payment.CardExpiryMonth, ExpYear = payment.CardExpiryYear, Cvc = payment.CardCVV } }; ret = 60; var paymentMethodService = new PaymentMethodService(); var paymentMethod = paymentMethodService.Create(paymentMethodOptions); err = err + ", paymentMethodId=" + Tools.NullToString(paymentMethod.Id); ret = 70; var customerOptions = new CustomerCreateOptions { Name = payment.CardName, // (payment.FirstName + " " + payment.LastName).Trim(), Email = payment.EMail, Phone = payment.PhoneCell, PaymentMethod = paymentMethod.Id }; ret = 80; var customerService = new CustomerService(); var customer = customerService.Create(customerOptions); err = err + ", customerId=" + Tools.NullToString(customer.Id); // if ( payment.PaymentDescription.Length < 1 ) // payment.PaymentDescription = "CareAssist"; // else if ( payment.PaymentDescription.Length > 22 ) // payment.PaymentDescription = payment.PaymentDescription.Substring(0,22); // Stripe needs a minimum payment of 50 US cents var paymentIntentOptions = new PaymentIntentCreateOptions { Amount = 050, // payment.PaymentAmount, Currency = "usd", // payment.CurrencyCode.ToLower(), // Must be "usd" not "USD" StatementDescriptor = payment.PaymentDescriptionLeft(22), Customer = customer.Id, PaymentMethod = paymentMethod.Id, Description = payment.MerchantReference, ConfirmationMethod = "manual" }; ret = 40; var paymentIntentService = new PaymentIntentService(); var paymentIntent = paymentIntentService.Create(paymentIntentOptions); err = err + ", paymentIntentId=" + Tools.NullToString(paymentIntent.Id); ret = 50; var confirmOptions = new PaymentIntentConfirmOptions { PaymentMethod = paymentMethod.Id, ReturnUrl = url }; ret = 60; var paymentConfirm = paymentIntentService.Confirm(paymentIntent.Id, confirmOptions); payRef = paymentConfirm.Id; err = err + ", paymentConfirmId=" + Tools.NullToString(payRef); ret = 70; strResult = paymentConfirm.StripeResponse.Content; d3Form = Tools.JSONValue(strResult, "url", "next_action"); d3Form = Tools.JSONRaw(d3Form); resultMsg = Tools.JSONValue(strResult, "status"); ret = 80; resultCode = paymentConfirm.StripeResponse.ToString(); int k = resultCode.ToUpper().IndexOf(" STATUS="); err = err + ", StripeResponse=" + Tools.NullToString(resultCode); ret = 90; Tools.LogInfo("ThreeDSecurePayment/60", "strResult=" + strResult, 221, this); string sql = "exec sp_WP_PaymentRegister3DSecA @ContractCode=" + Tools.DBString(payment.MerchantReference) + ",@ReferenceNumber=" + Tools.DBString(payRef) + ",@Status='77'"; // Means payment pending if (languageCode.Length > 0) { sql = sql + ",@LanguageCode=" + Tools.DBString(languageCode); } if (languageDialectCode.Length > 0) { sql = sql + ",@LanguageDialectCode=" + Tools.DBString(languageDialectCode); } using (MiscList mList = new MiscList()) mList.ExecQuery(sql, 0, "", false, true); Tools.LogInfo("ThreeDSecurePayment/80", "PayRef=" + payRef + "; SQL=" + sql + "; " + d3Form, 10, this); return(0); } catch (Exception ex) { Tools.LogException("ThreeDSecurePayment/99", "Ret=" + ret.ToString(), ex, this); } return(ret); }
public override int TokenPayment(Payment payment) { if (!EnabledFor3d(payment.TransactionType)) { return(590); } int ret = 610; payRef = ""; strResult = ""; err = ""; resultMsg = "Fail"; resultCode = "981"; Tools.LogInfo("TokenPayment/10", "Merchant Ref=" + payment.MerchantReference, 10, this); try { ret = 620; StripeConfiguration.ApiKey = payment.ProviderPassword; // Secret key ret = 624; err = err + ", customerId=" + Tools.NullToString(payment.CustomerID) + ", paymentMethodId=" + Tools.NullToString(payment.PaymentMethodID) + ", tokenId=" + Tools.NullToString(payment.CardToken); ret = 630; var paymentIntentOptions = new PaymentIntentCreateOptions { Amount = payment.PaymentAmount, Currency = payment.CurrencyCode.ToLower(), // Must be "usd" not "USD" StatementDescriptor = payment.PaymentDescriptionLeft(22), Customer = payment.CustomerID, PaymentMethod = payment.PaymentMethodID, Description = payment.MerchantReference, ConfirmationMethod = "manual" // SetupFutureUsage = "off_session", // Confirm = true, // PaymentMethodData = new PaymentIntentPaymentMethodDataOptions // { // Type = "card" // }, }; // Create a separate mandate // string mandateId = ""; // if ( payment.MandateDateTime > Constants.DateNull && payment.MandateIPAddress.Length > 2 ) // { // ret = 640; // var mandate = new Mandate // { // CustomerAcceptance = new MandateCustomerAcceptance // { // AcceptedAt = payment.MandateDateTime, // Online = new MandateCustomerAcceptanceOnline // { // IpAddress = payment.MandateIPAddress, // UserAgent = payment.MandateBrowser // } // } // }; // mandateId = mandate.Id; // err = err + ", mandateId="+Tools.NullToString(mandateId); // } // else // err = err + ", No mandate"; ret = 690; var paymentIntentService = new PaymentIntentService(); var paymentIntent = paymentIntentService.Create(paymentIntentOptions); err = err + ", paymentIntentId=" + Tools.NullToString(paymentIntent.Id); ret = 700; var confirmOptions = new PaymentIntentConfirmOptions { PaymentMethod = payment.PaymentMethodID, OffSession = true // Mandate = mandateId // MandateData = new PaymentIntentMandateDataOptions // { // CustomerAcceptance = new PaymentIntentMandateDataCustomerAcceptanceOptions // { // AcceptedAt = payment.MandateDateTime, // Online = new PaymentIntentMandateDataCustomerAcceptanceOnlineOptions // { // IpAddress = payment.MandateIPAddress, // UserAgent = payment.MandateBrowser // } // } // } }; if (payment.MandateDateTime > Constants.DateNull && payment.MandateIPAddress.Length > 2) { ret = 710; confirmOptions.MandateData = new PaymentIntentMandateDataOptions { CustomerAcceptance = new PaymentIntentMandateDataCustomerAcceptanceOptions { AcceptedAt = payment.MandateDateTime, Type = "online", Online = new PaymentIntentMandateDataCustomerAcceptanceOnlineOptions { IpAddress = payment.MandateIPAddress, UserAgent = payment.MandateBrowser } } }; } ret = 720; var paymentConfirm = paymentIntentService.Confirm(paymentIntent.Id, confirmOptions); payRef = paymentConfirm.Id; err = err + ", paymentConfirmId=" + Tools.NullToString(payRef); ret = 730; strResult = paymentConfirm.StripeResponse.Content; resultMsg = Tools.JSONValue(strResult, "status"); resultCode = paymentConfirm.StripeResponse.ToString(); int k = resultCode.ToUpper().IndexOf(" STATUS="); ret = 740; err = err + ", StripeResponse=" + Tools.NullToString(resultCode); if (k > 0) { ret = 750; resultCode = resultCode.Substring(k + 8).Trim(); k = resultCode.IndexOf(" "); if (k > 0) { resultCode = resultCode.Substring(0, k); } } else { resultCode = "989"; } ret = 760; err = err + ", strResult=" + Tools.NullToString(strResult) + ", resultCode=" + Tools.NullToString(resultCode); // mandate = null; paymentIntentService = null; paymentIntent = null; confirmOptions = null; paymentConfirm = null; if (!resultCode.StartsWith("2") || payRef.Length < 1) { resultCode = (resultMsg.Length > 0 ? resultMsg : "Fail"); // resultCode = "Fail/" + resultCode + ( resultMsg.Length > 0 ? " : " + resultMsg : "" ); Tools.LogInfo("TokenPayment/197", "Ret=" + ret.ToString() + err, 231, this); } else if (resultMsg.ToUpper().StartsWith("SUCCE") || resultMsg.Length == 0) { ret = 0; resultCode = "Success"; // resultCode = "Success/" + resultCode; // Tools.LogInfo ("TokenPayment/189","Ret=0" + err,255,this); } else { resultCode = resultMsg; } } catch (Exception ex) { resultCode = ex.Message; // resultCode = "Fail/" + ret.ToString() + " : " + ex.Message + ( resultMsg.Length > 0 ? " (" + resultMsg + ")" : "" ); err = "Ret=" + ret.ToString() + err; Tools.LogInfo("TokenPayment/198", err, 231, this); Tools.LogException("TokenPayment/199", err, ex, this); } return(ret); }