Skip to content

Commit

Permalink
Merge pull request #16 from CyberSource/release-25.1.0
Browse files Browse the repository at this point in the history
Flex microform v2 upgrade
  • Loading branch information
ohernandovisa authored Feb 21, 2025
2 parents 5b4638d + 550196c commit 2b9ddda
Show file tree
Hide file tree
Showing 23 changed files with 334 additions and 87 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

* **Description:** Cybersource, a Visa solution, is the only global, modular payment management platform built on secure Visa infrastructure with the payment reach and fraud insights of a massive $500B+ global processing network. You can find out more about what Cybersource does [here](https://www.cybersource.com/en-gb.html)
* **Categories:** Payment Processing, Fraud Detection, Address Validation, Tax Computation
* **Version:** 24.4.0
* **Last Certification Date:** September 2024
* **Version:** 25.1.0
* **Last Certification Date:** January 2025
* **Supports SFRA v7.0**
* **JavaScript Controllers Friendly:** **YES**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

$(document).ready(function () {
var captureContext = JSON.parse($('#flexTokenResponse').val()).keyId;
var captureContext = $('#flexTokenResponse').val();
var flex = new Flex(captureContext); // eslint-disable-line no-undef
var customStyles = {
input: {
Expand All @@ -25,7 +25,7 @@ $(document).ready(function () {
color: '#a94442'
}
};
var microform = flex.microform({
var microform = flex.microform("card",{
styles: customStyles
});
var number = microform.createField('number');
Expand Down Expand Up @@ -107,7 +107,7 @@ $(document).ready(function () {
var decodedJwt = parseJwt(response);
document.getElementById('cardNumber').valid = true;
$('#flex-response').val(response);
$('#cardNumber').val(decodedJwt.data.number);
$('#cardNumber').val(decodedJwt.content.paymentInformation.card.number.maskedValue);

if ($('.submit-payment').length === 1) {
$('.submit-payment').trigger('click');
Expand Down Expand Up @@ -137,7 +137,7 @@ $(document).ready(function () {
case 'discover':
correctCardType = 'Discover';
break;
case 'diners-club':
case 'dinersclub':
correctCardType = 'DinersClub';
break;
case 'maestro':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
background-size: contain;
}

&[data-type="diners-club"]::after {
&[data-type="dinersclub"]::after {
background-image: url('../../images/payment-types.png');
background-size: auto;
background-position: -230px -205px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@
<div id="cardNumber-container" class="form-control"></div>
<div class="invalid-feedback"></div>
</div>
<isif condition="${pdict.flexTokenResult == null}">
<div class="alert alert-danger">${flexError}</div>
</isif>
<isif condition="${pdict.flexTokenResult == null}">
<div class="alert alert-danger">${flexError}</div>
</isif>
</div>
</div>
</div>

<div class="row">
<div class="col-12">
<div class="form-group securityCode" data-cardNumber="${Resource.msg('securityCode.placeholder','cybersource',null)}">
<label class="form-control-label" for="securityCode">${Resource.msg('field.credit.card.security.code','creditCard',null)}</label>
<div class="form-group securityCode"data-cardNumber="${Resource.msg('securityCode.placeholder', 'cybersource', null)}">
<label class="form-control-label"
for="securityCode">${Resource.msg('field.credit.card.security.code', 'creditCard', null)}</label>
<div class="security-code-wrapper">
<div id="securityCode-container" class="form-control"></div>
<div class="invalid-feedback"></div>
</div>
<isif condition="${pdict.flexTokenResult == null}">
<div class="alert alert-danger">${flexError}</div>
</isif>
<isif condition="${pdict.flexTokenResult == null}">
<div class="alert alert-danger">${flexError}</div>
</isif>
</div>
</div>
</div>

<isif condition="${pdict.flexTokenResult != null}" >
<isset name="flextoken" value="${pdict.flexTokenResult}" scope="page" />
<input type="hidden" value="${JSON.stringify(flextoken)}" name="flexTokenResponse" id="flexTokenResponse"/>
<input type="hidden" value="${JSON.stringify(flextoken.jwk)}" name="flextokenObj" id="flextokenObj"/>
<isif condition="${pdict.flexTokenResult != null}">
<isset name="flextoken" value="${pdict.flexTokenResult}" scope="page" />
<input type="hidden" value="${flextoken}" name="flexTokenResponse" id="flexTokenResponse" />
</isif>

<iscomment>Secure Acceptance Flex MicroForm </iscomment>
Expand All @@ -48,10 +48,5 @@
</div>

<iscomment>Secure Acceptance Flex Microform Scripts </iscomment>

<isif condition="${dw.system.System.getInstanceType()!= 2}">
<script src="https://testflex.cybersource.com/cybersource/assets/microform/0.11/flex-microform.min.js"></script>
<iselse>
<script src="https://flex.cybersource.com/cybersource/assets/microform/0.11/flex-microform.min.js"></script>
</iselse>
</isif>

<script src = '${pdict.clientLibrary}' integrity = '${pdict.clientLibraryIntegrity}' crossorigin="anonymous"></script>
10 changes: 8 additions & 2 deletions cartridges/int_cybs_sfra_base/cartridge/apiClient/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ _exports.prototype.callApi = function (path, httpMethod, pathParams, queryParams
var merchantKeyId = this.merchantConfig.getMerchantKeyID();
var merchantSecretKey = this.merchantConfig.getMerchantsecretKey();
var payload = "";
var Constants = require('../apiClient/constants');

var url = this.buildUrl(path, pathParams, queryParams);

Expand All @@ -210,7 +211,8 @@ _exports.prototype.callApi = function (path, httpMethod, pathParams, queryParams
if (!bodyParam.clientReferenceInformation) {
bodyParam.clientReferenceInformation = {};
}

bodyParam.clientReferenceInformation.applicationName = Constants.APPLICATION_NAME;
bodyParam.clientReferenceInformation.applicationVersion = Constants.APPLICATION_VERSION;
bodyParam.clientReferenceInformation.partner = {
solutionId: this.merchantConfig.getSolutionId(),
developerId: this.merchantConfig.getDeveloperId()
Expand Down Expand Up @@ -245,7 +247,11 @@ _exports.prototype.callApi = function (path, httpMethod, pathParams, queryParams

if (response.ok) {
var responseObj = response.object;
callback(JSON.parse(responseObj), false, response);
if(path === '/microform/v2/sessions'){
callback(responseObj, false, response);
}else{
callback(JSON.parse(responseObj), false, response);
}
} else {
callback(response.errorMessage, response.error, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@

var authNames = [];
var contentTypes = ['application/json;charset=utf-8'];
var accepts = ['application/hal+json;charset=utf-8'];
var accepts = ['application/json'];
var returnType = KmsV2KeysAsymGet200Response;

return this.apiClient.callApi(
'/kms/v2/keys-asym/{keyId}', 'GET',
'/flex/v2/public-keys/{keyId}', 'GET',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
var returnType = FlexV1KeysPost200Response;

return this.apiClient.callApi(
'/flex/v1/keys', 'POST',
'/microform/v2/sessions', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ module.exports = {
PRODUCTION_URL: "",
SANDBOX_RUN_ENV: "cybersource.environment.sandbox",
PRODUCTION_RUN_ENV: "cybersource.environment.production",
APPLICATION_NAME: "Salesforce B2C(REST)",
APPLICATION_VERSION: "25.1.0",

/* Digest Constants*/
SIGNATURE_ALGORITHAM: "SHA-256=",
HmacSHA256: "HmacSHA256",

/* Flex microform constants */
ENCRYPTION_TYPE: "RsaOaep256",
CLIENT_VERSION : "v2",



/* Logging Labels*/
BEGIN_TRANSACTION: "START > =======================================",
END_TRANSACTION: "END > =========================================",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var LogfileMaxSize = '5242880'; // 10 MB In Bytes
* Send this value in all requests that are sent through the partner solution. CyberSource assigns the ID to the partner.
* Note When you see a partner ID of 999 in reports, the partner ID that was submitted is incorrect.
*/
var SolutionId = '6EIFFEUD';
var SolutionId = 'FTN2UOLO';

var CruiseDDCEndPoint = {
Stage: 'https://centinelapistag.cardinalcommerce.com/V1/Cruise/Collect',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ server.post('handlingConsumerAuthResponse', server.middleware.https, function (r
}

// eslint-disable-next-line
else if (authenticateResponse.errorInformation.reason === 'CUSTOMER_AUTHENTICATION_REQUIRED' && session.custom.Flag3ds === false) {
else if ((authenticateResponse.errorInformation ? authenticateResponse.errorInformation.reason === 'CUSTOMER_AUTHENTICATION_REQUIRED' : false) && session.custom.Flag3ds === false) {
session.custom.Flag3ds = true;
// eslint-disable-next-line no-shadow
res.render('payerAuthentication/scaRedirect', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ var configObject = require('../configuration/index');
if (configObject.cartridgeEnabled) {
server.get('CreateFlexToken', server.middleware.https, function (req, res, next) {
var Flex = require('~/cartridge/scripts/http/payments');
var flexResult = Flex.createFlexKey(null);
res.render('secureAcceptanceFlexMicroformContent', {
flexTokenResult: flexResult
});
next();
var flexResult = Flex.createFlexKey();
var parsedPayload = Flex.jwtDecode(flexResult);
if(parsedPayload != null){
var clientLibrary = parsedPayload.ctx[0].data.clientLibrary;
var clientLibraryIntegrity = parsedPayload.ctx[0].data.clientLibraryIntegrity;
res.render('secureAcceptanceFlexMicroformContent', {
flexTokenResult: flexResult,
clientLibrary: clientLibrary,
clientLibraryIntegrity: clientLibraryIntegrity
});
next();
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function processForm(req, paymentForm, viewFormData) {
case 'discover':
correctCardType = 'Discover';
break;
case 'diners-club':
case 'dinersclub':
correctCardType = 'DinersClub';
break;
case 'maestro':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,41 @@ function createWebhookSubscription(callback) {
);
}

function deleteSusbscriprion(id, callback){
var postBody = null;

var pathParams = {
'webhookId' : id
};
var queryParams = {};
var headerParams = {};
var formParams = {};

var authNames = [];
var contentTypes = ['application/json;charset=utf-8'];
var accepts = ['application/json;charset=utf-8'];
var returnType = {};
apiClient.instance.callApi(
'/notification-subscriptions/v1/webhooks/{webhookId}' , 'DELETE',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, callback
);
}
function createNetworkTokenSubscription() {
retrieveAllCreatedWebhooks(function (data, error, response) {
if (data.webhookId) {
Logger.error('Subscription already exists');
if (data[0].webhookId) {
var obj = CustomObjectMgr.getCustomObject("Network Tokens Webhook", merchantId);
if (obj == null) {
deleteSusbscriprion(data[0].webhookId, function (data, error, responseData) {
if(responseData.status === 'OK'){
createNetworkTokenSubscription();
}
});
}
}
if (error) {
data = JSON.parse(data);
if (data.statusCode === 404 && data.errorDescription === 'Record Not Found') {
if (data.statusCode === 404) {
var key = '';
createWebhookSecurityKey(function (data, error, response) {
if (!error) {
Expand All @@ -136,7 +163,10 @@ function createNetworkTokenSubscription() {
}
});
Transaction.wrap(function () {
var obj = CustomObjectMgr.createCustomObject('Network Tokens Webhook', merchantId);
var obj = CustomObjectMgr.getCustomObject("Network Tokens Webhook", merchantId);
if (obj == null) {
obj = CustomObjectMgr.createCustomObject('Network Tokens Webhook', merchantId);
}
obj.custom.SecurityKey = key;
obj.custom.SubscriptionId = webhookId;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,10 @@ function paConsumerAuthenticate(billingDetails, referenceInformationCode, total,
} else {
try {
var parsedData = JSON.parse(data);
var reasonCodeObject = parsedData.errorInformation.details.filter(function (e) { return e.field === 'reasonCode'; }).pop();
var reasonCodeObject = parsedData;
if(parsedData.errorInformation != null){
reasonCodeObject = parsedData.errorInformation.details.filter(function (e) { return e.field === 'reasonCode'; }).pop();
}
result = {
status: reasonCodeObject.reason
};
Expand Down
Loading

0 comments on commit 2b9ddda

Please sign in to comment.