PaymentScriptInfo GetPaymentScriptProvider(PaymentOptionConfiguration configuration, string paymentMethod) { if (configuration.PayPalExpressUseIntegratedCheckout && (paymentMethod == AppLogic.ro_PMPayPalExpress)) { var environment = configuration.UseLiveTransactions ? "production" : "sandbox"; var scriptTarget = "PayPalExpressScriptContainerIdentifier"; var urlBuilderEndpoint = UrlHelper.Action(ActionNames.StartPayPalExpress, ControllerNames.PayPalExpress); return(new PaymentScriptInfo( paymentScripts: new IPaymentScript[] { new PaymentScriptSource(UrlHelper.Content("~/scripts/paypalexpress.js")), new PaymentAdHocScript(string.Format( "PayPalExpress.init('{0}','{1}','{2}','{3}');", configuration.PayPalApiUsername, environment, scriptTarget, urlBuilderEndpoint)), new PaymentScriptSource("//www.paypalobjects.com/api/checkout.js", async: true), }, scriptTarget: scriptTarget)); } else if (paymentMethod == AppLogic.ro_PMAmazonPayments) { return(new PaymentScriptInfo( paymentScripts: new IPaymentScript[] { new PaymentAdHocScript(string.Format(@" window.onAmazonLoginReady = function() {{ amazon.Login.setClientId('{0}'); }};" , configuration.AmazonPaymentsClientId)), new PaymentScriptSource("https://static-na.payments-amazon.com/OffAmazonPayments/us/sandbox/js/Widgets.js"), new PaymentAdHocScript(string.Format(@" adnsf$(function() {{ OffAmazonPayments.Button('AmazonPayButton', '{0}', {{ type: 'PwA', color: 'Gold', size: 'small', authorization: function() {{ amazon.Login.authorize({{ scope: 'profile payments:widget payments:shipping_address' }}, '{1}'); }} }}) }});" , configuration.AmazonPaymentsMerchantId, configuration.AmazonPaymentsCallbackEndpoint)) }, scriptTarget: "AmazonPayButton")); } return(null); }
PaymentOption GetPaymentOption(PaymentOptionConfiguration configuration, PaymentMethodInfo paymentMethodInfo, Customer customer, ShoppingCart cart, int defaultOrderIndex) { return(new PaymentOption( info: paymentMethodInfo, available: IsAvailable(paymentMethodInfo, customer, cart), displayOrder: PaymentOptionOrdering.ContainsKey(paymentMethodInfo.Name) ? PaymentOptionOrdering[paymentMethodInfo.Name] : defaultOrderIndex, selectionImage: GetImage(configuration, paymentMethodInfo.Name), editUrl: GetEditUrl(paymentMethodInfo), isOffsiteForDisplay: OffsitePaymentOptionsForDisplay.Contains(paymentMethodInfo.Name, StringComparer.OrdinalIgnoreCase), isEditable: GetEditableState(paymentMethodInfo), paymentScriptProvider: GetPaymentScriptProvider(configuration, paymentMethodInfo.Name))); }
string GetImage(PaymentOptionConfiguration configuration, string paymentMethod) { if (paymentMethod == AppLogic.ro_PMPayPalExpress) { return(configuration.PayPalExpressButtonImageUrl); } else if (paymentMethod == AppLogic.ro_PMPayPalCredit) { return(configuration.PayPalCreditButtonImageUrl); } else { return(null); } }
IEnumerable <string> GetPaymentScripts(HttpContextBase httpContext, PaymentOptionConfiguration configuration, string paymentMethod) { // All script ordering below is very intentional. Be careful when changing. if (paymentMethod == AppLogic.ro_PMPayPalExpress) { return new[] { ClientScriptRegistry.RegisterScriptBundle( httpContext, bundleUrl: ScriptBundlePaths.CheckoutBundle, urls: new[] { ScriptPaths.PaypalExpress, }, sharedDependencies: new[] { ScriptPaths.JQuery.AdnsfAlias, }), ClientScriptRegistry.RegisterInlineScript( httpContext, name: InlineScripts.OnPayPalReady, content: string.Format( "PayPalExpress.init('{0}','{1}','{2}','{3}');", configuration.PayPalApiUsername, configuration.UseLiveTransactions ? "production" : "sandbox", GetPaymentScriptTarget(paymentMethod), UrlHelper.Action( ActionNames.StartPayPalExpress, ControllerNames.PayPalExpress)), addScriptTag: true, dependencies: new[] { ScriptPaths.PaypalExpress, }), ClientScriptRegistry.RegisterScriptReference( httpContext, url: "//www.paypalobjects.com/api/checkout.js", async: true, dependencies: new[] { InlineScripts.OnPayPalReady, }) } } ; if (paymentMethod == AppLogic.ro_PMAmazonPayments) { return new[] { ClientScriptRegistry.RegisterScriptBundle( httpContext, bundleUrl: ScriptBundlePaths.AmazonBundle, urls: new[] { ScriptPaths.AmazonPayments }, sharedDependencies: new[] { ScriptPaths.JQuery.AdnsfAlias }), ClientScriptRegistry.RegisterInlineScript( httpContext, name: InlineScripts.OnAmazonLoginReady, content: string.Format( "AdnsfAmazonPayments.initClientId('{0}');", configuration.AmazonPaymentsClientId), addScriptTag: true, dependencies: new[] { ScriptPaths.AmazonPayments }), ClientScriptRegistry.RegisterScriptReference( httpContext, url: AppLogic.AppConfigBool("UseLiveTransactions") ? AppLogic.AppConfig("AmazonPayments.LiveScriptUrl") : AppLogic.AppConfig("AmazonPayments.SandboxScriptUrl"), dependencies: new[] { ScriptPaths.AmazonPayments, InlineScripts.OnAmazonLoginReady, }), ClientScriptRegistry.RegisterInlineScript( httpContext, content: string.Format( "AdnsfAmazonPayments.checkoutButton('{0}','{1}','{2}');", GetPaymentScriptTarget(paymentMethod), configuration.AmazonPaymentsMerchantId, configuration.AmazonPaymentsCallbackEndpoint), addScriptTag: true, dependencies: new[] { ScriptPaths.AmazonPayments, AppLogic.AppConfigBool("UseLiveTransactions") ? AppLogic.AppConfig("AmazonPayments.LiveScriptUrl") : AppLogic.AppConfig("AmazonPayments.SandboxScriptUrl") }) } } ; return(null); } string GetPaymentScriptTarget(string paymentMethod) { if (paymentMethod == AppLogic.ro_PMPayPalExpress) { return("PayPalExpressScriptContainerIdentifier"); } if (paymentMethod == AppLogic.ro_PMAmazonPayments) { return("AmazonPayButton"); } return(null); }