Incorrect Redirect URL for External Payments
On releases of Elbrus and Vinson, the checkout process that uses an external payment system does not correctly cancel the process and return to the SuiteCommerce site. Instead, when you click Cancel while using an external payment system, a 404 error occurs. This error occurs due to an incorrect URL variable value in the OrderWizard.Module.PaymentMethod module.
To implement this patch, you must extend the prototype
object for the render()
method in OrderWizard.Module.PaymentMethod.External.js for the OrderWizard.Module.PaymentMethod module. You can download the code samples described in this procedure here: IncorrectRedirectURLforExternalPaymentsElbrus.zip or IncorrectRedirectURLforExternalPaymentsVinson.zip.
Before proceeding, familiarize yourself with Best Practices for Customizing SCA.
Step 1: Extend the OrderWizard.Module.PaymentMethod.External.js File
-
If you have not done so already, create a directory to store your custom module.
Give this directory a name similar to the module being customized. For example, create
Modules/extensions/OrderWizard.Module.PaymentMethod.Extension@1.0.0
. -
In your new OrderWizard.Module.PaymentMethod.Extension@1.0.0 directory, create a subdirectory called
JavaScript
.For example:
Modules/extensions/OrderWizard.Module.PaymentMethod.Extension@1.0.0/JavaScript
-
In your new JavaScript subdirectory, create a JavaScript file to extend OrderWizard.Module.PaymentMethod.External.js.
Name this file according to best practices. For example:
OrderWizard.Module.PaymentMethod.External.Extension.js
-
Open this file and extend the
render()
method as shown in the following code snippet.define( 'OrderWizard.Module.PaymentMethod.External.Extension' , [ 'OrderWizard.Module.PaymentMethod' , 'Session' , 'OrderPaymentmethod.Model' , 'order_wizard_paymentmethod_external_module.tpl' , 'Backbone' , 'underscore' , 'SC.Configuration' , 'Utils' ] , function ( OrderWizardModulePaymentMethod , Session , OrderPaymentmethodModel , order_wizard_paymentmethod_external_module_tpl , Backbone , _ , Configuration , Utils ) { 'use strict'; _.extend(OrderWizard.Module.PaymentMethod.prototype, { render: function () { var n = Configuration.get('siteSettings.id') , status_accept_value = Configuration.get('siteSettings.externalCheckout.' + this.options.record_type.toUpperCase() + '.statusAcceptValue' , 'ACCEPT') , status_reject_value = Configuration.get('siteSettings.externalCheckout.' + this.options.record_type.toUpperCase() + '.statusRejectValue' , 'REJECT') , status_parameter_name = Configuration.get('siteSettings.externalCheckout.' + this.options.record_type.toUpperCase() + '.statusParameterName' , 'status') , origin = window.location.origin ? window.location.origin : (window.location.protocol + '//' + window.location.hostname + (window.location.port ? (':' + window.location.port) : '')) , url = origin + _.getAbsoluteUrl('external_payment.ssp') , current_touchpoint = Configuration.get('currentTouchpoint') , thankyouurl_parameters = {n: n, externalPaymentDone: 'T', touchpoint: current_touchpoint, recordType: this.options.record_type || 'salesorder' } , errorurl_parameters = {n: n, externalPaymentDone: 'T', touchpoint: current_touchpoint, recordType: this.options.record_type || 'salesorder' } , returnurl_parameters = {n: n, externalPaymentDone: 'T', touchpoint: current_touchpoint, recordType: this.options.record_type || 'salesorder'}; thankyouurl_parameters[status_parameter_name] = status_accept_value; errorurl_parameters[status_parameter_name] = status_reject_value; if (this.options.prevent_default) { var prevent_default_parameter_name = Configuration.get('siteSettings.externalCheckout.' + this.options.record_type.toUpperCase() + '.preventDefaultParameterName', 'preventDefault') , prevent_default_value = Configuration.get('siteSettings.externalCheckout.' + this.options.record_type.toUpperCase() + '.preventDefaultValue', 'T'); thankyouurl_parameters[prevent_default_parameter_name] = prevent_default_value; errorurl_parameters[prevent_default_parameter_name] = prevent_default_value; returnurl_parameters[prevent_default_parameter_name] = prevent_default_value; } this.paymentMethod = new OrderPaymentmethodModel({ type: 'external_checkout_' + this.options.paymentmethod.key , isexternal: 'T' , internalid: this.options.paymentmethod.internalid , merchantid: this.options.paymentmethod.merchantid , key: this.options.paymentmethod.key , thankyouurl: Utils.addParamsToUrl(url, thankyouurl_parameters) // Commerce API , errorurl: Utils.addParamsToUrl(url, errorurl_parameters) // Commerce API , returnurl: Utils.addParamsToUrl(url, returnurl_parameters) // SuiteScript }); this._render(); } }) });
-
Save the file.
Step 2: Prepare the Developer Tools For Your Customization
-
Open your new OrderWizard.Module.PaymentMethod.Extension@1.0.0 module directory.
-
Create a file in this directory and name it ns.package.json.
Modules/extensions/OrderWizard.Module.PaymentMethod.Extension@1.0.0/ns.package.json
-
Build the ns.package.json file using the following code:
{ "gulp": { "javascript": [ "JavaScript/*.js" ] } }
-
Open the distro.json file. This is located in your root directory.
-
Add your custom modules to the
modules
object.Your code should look similar to the following example:
{ "name": "SuiteCommerce Advanced Vinson Release", "version": "2.0", "buildToolsVersion": "1.2.1", "folders": { "modules": "Modules", "suitecommerceModules": "Modules/suitecommerce", "thirdPartyModules": "Modules/third_parties", "distribution": "LocalDistribution", "deploy": "DeployDistribution" }, "modules": { "extensions/OrderWizard.Module.PaymentMethod.Extension": "1.0.0", "suitecommerce/Account": "2.2.0", ...
This ensures that the Gulp tasks include your module when you deploy. In this example, the custom modules are added at the beginning of the list of modules. However, you can add the modules anywhere in the
modules
object. The order of precedence in this list does not matter. -
Add
OrderWizard.Module.PaymentMethod.Extension
as a dependency to SCA entry point within theSC.Checkout.Starter
entrypoint of the JavaScript array.Your distro.js file should look similar to the following:
"tasksConfig": { //... "javascript": [ //... { "entryPoint": "SC.Checkout.Starter", "exportFile": "checkout.js", "dependencies": [ "Backbone.View.Plugins", "OrderWizard.Module.PaymentMethod.Extension", // ... ], //...
-
Save the distro.json file.
Step 3: Test and Deploy Your Customization
-
Test your source code customizations on a local server (see Test SCA Customizations on a Local Server) or deploy them to your NetSuite account (see Deploy SCA Customizations to NetSuite). If you are currently running SCA on a local server, your changes should appear on your local site immediately.
-
Confirm your results.
Upon successful deployment, the Cancel button for an external payment system redirects back to the SuiteCommerce site from where it was launched.