Here you can find some examples of advanced workflow customization for COPYandPAY. Each of the examples provided use the wpwlOptions variable, the full reference for which can be found on our COPYandPAY API Reference.
Please note that JavaScript examples from COPYandPAY can be used only when including jQuery.
You can add additional parameters to the payment form using the wpwlOptions variable, prior to loading COPYandPAY. In the example above, we add a custom parameter to the payment form for recording the number of installments requested by the customer. The steps are listed below.
Prepare the checkout
Using the wpwlOptions API onLoad event, add the custom field HTML to the payment form
Set the name of the html input field to your API parameter e.g. recurring.numberOfInstallments
var wpwlOptions = { style:"card",onReady:function() { var numberOfInstallmentsHtml = '<div class="wpwl-label wpwl-label-custom" style="display:inline-block">Number of Installments</div>' +
'<div class="wpwl-wrapper wpwl-wrapper-custom" style="display:inline-block">'+ '<select name="recurring.numberOfInstallments"><option value="1">1</option><option value="3">3</option><option value="5">5</option></select>' +
'</div>'; $('form.wpwl-form-card').find('.wpwl-button').before(numberOfInstallmentsHtml); } }
Change label
You can change a label in the payment form using the wpwlOptions variable, prior to loading the COPYandPAY payment widget. In the following example, we'll change the credit card brand label in the payment form.
Prepare the order
Using the wpwlOptions API onLoad event, use a JQuery selector to set the desired value of the label
var wpwlOptions = {onReady:function() {$('.wpwl-label-brand').html('Card Brand'); }}
Create custom UI - headling
You can change the behavior of the payment page when there are multiple types of payment methods using the wpwlOptions variable, prior to loading the COPYandPAY payment widget.
Prepare the checkout
Using the wpwlOptions API onLoad event, iterate through each .wpwl-container adding custom HTML before the container
Create a JQuery click handler to show the container on click.
/* create custom UI */functionwrapElement(element) {var id =$(element).attr("id");var wrapId ="wrap_"+ id;$(element).wrap('<div id="'+wrapId+'"></div>"'); return$('#'+wrapId);} var methodMapping = {"card":" Click to pay with card","prepayment-BOLETO":" Click to pay with Boleto","virtualAccount-PAYPAL":" Click to pay with PayPal",}var wpwlOptions = { style:"plain",onReady:function() {$('.wpwl-container').each(function() {var id =$(this).attr("id"); wrapElement(this).hide().before("<h4 class='payHead'>" + methodMapping[id.substring(0, id.lastIndexOf("_"))] + "</h4>");
$(this).hide(); });$("h4").click(function() {$(this).next().slideToggle(); }); }}
Create custom UI - Box model
You can change the behavior of the payment page when there are multiple types of payment methods using the wpwlOptions variable, prior to loading the COPYandPAY payment widget.
Prepare the checkout
Using the wpwlOptions API onReady event and make some adaptions to the containers.
Create a JQuery click handler to show the container on click.
It is possible to use COPYandPAY to temporarily store the payment information after submission, rather than executing it straight away. This can be useful if you want to display an order summary page before committing the payment. This can be done using the wpwlOptions variable, prior to loading the COPYandPAY.
To commit the payment after the summary page has been displayed, you can include the following form on the summary page. When the submit button is pressed, the payment will be executed.
var wpwlOptions = {onReady:function() { var createRegistrationHtml = '<div class="customLabel">Store payment details?</div><div class="customInput"><input type="checkbox" name="createRegistration" value="true" /></div>';
$('form.wpwl-form-card').find('.wpwl-button').before(createRegistrationHtml); }}
Field order in the payment form
COPYandPAY allows you to modify the order of the fields in the payment form. As a result of this reordering, the order in which fields get tabbed will be adjusted accordingly. For details, please take a look at the JavaScript section in the following integration form.
Use the mandatoryBillingFields options in order to control if some field will be validated (for empty value) or not.
MaskCvv page
It is possible to mask cvv on COPYandPAY, which can be done by setting "maskCvv" to true in wpwlOptions variable, prior to loading the COPYandPAY payment widget.
To influence the brand detection behavior, use the following options in wpwlOptions variable prior to loading the COPYandPAY payment widget.
var wpwlOptions = {
// Enable brand detection
brandDetection: true,
// Use our internal BIN list to precisely detect brands
brandDetectionType: "binlist",
// Give priority to detected brands
brandDetectionPriority: ["CARTEBANCAIRE","VISA","MAESTRO","MASTER"]
Sometimes you might want to hide some brands when multiple brands are detected. This can guide the shopper to select your preferred brand. There are several options to implement this feature:
If you use your own brand images, implement onDetectBrand. This method is called with a list of detected brands. With this information you can choose to show or hide your images.
Use COPYandPAY images the "logos" style. By default this style dynamically displays all detected brands as you type the card number. You can implement onChangeBrand to change this behavior.
The following snippet gives an example how to implement Option 2. Except for the first detected brand, all other brands are hidden behind three dots (...). The hidden brands are shown only after the three dots are clicked.
Try for example the BIN 513678 from which multiple brands are detected.
var wpwlOptions = {
style: "logos",
brandDetection: true,
brandDetectionType: "binlist",
brandDetectionPriority: ["CARTEBANCAIRE","VISA","MAESTRO","MASTER"],
// Optional. Use SVG images, if available, for better quality.
imageStyle: "svg",
onReady: function() {
ready = true;
},
onChangeBrand: function() {
hideBrands();
}
};
var ready = false;
var dotsClicked = false;
function hideBrands() {
if (!ready || dotsClicked) {
return;
}
// Clears all previous dots-hidden logos, if any
$(".wpwl-group-card-logos-horizontal > div").removeClass("dots-hidden");
// Selects all non-hidden logos. They are detected brands which otherwise would be shown by default.
var $logos = $(".wpwl-group-card-logos-horizontal > div:not(.wpwl-hidden)");
if ($logos.length < 2) {
return;
}
// Hides all except the first logo, and displays three dots (...)
$logos.first().after($("<div>...</div>").addClass("dots"));
$logos.filter(function(index) { return index > 0; }).addClass("dots-hidden");
// If ... is clicked, un-hides the logos
$(".dots").click(function() {
dotsClicked = true;
$(".dots-hidden").removeClass("dots-hidden");
$(this).remove();
});
}
Unload/Reload the Widget
In order to reload the widget, it's not enough to remove it from the page. You need to remove event bindings and stop the iframe communication, otherwise the previous widget will present unwanted error messages. To achieve that, use the wpwl.unload method and remove the static.min.js script.
After doing this, you can insert again the form with the brands and the paymentWidgets.js script in order to reload the widget.
The code below is an example of how to unload the widget.
var unloadWidget = function() {
if (window.wpwl !== undefined && window.wpwl.unload !== undefined) {
window.wpwl.unload();
$('script').each(function () {
if (this.src.indexOf('static.min.js') !== -1) {
$(this).remove();
}
});
}
};