Skip to content

Randomized Transaction Data Using FakerJS #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,7 @@ with the following code:
// For PRODUCTION use
const RunEnvironment = "api.cybersource.com";
```

## Disclaimer

Cybersource may allow Customer to access, use, and/or test a Cybersource product or service that may still be in development or has not been market-tested (“Beta Product”) solely for the purpose of evaluating the functionality or marketability of the Beta Product (a “Beta Evaluation”). Notwithstanding any language to the contrary, the following terms shall apply with respect to Customer’s participation in any Beta Evaluation (and the Beta Product(s)) accessed thereunder): The Parties will enter into a separate form agreement detailing the scope of the Beta Evaluation, requirements, pricing, the length of the beta evaluation period (“Beta Product Form”). Beta Products are not, and may not become, Transaction Services and have not yet been publicly released and are offered for the sole purpose of internal testing and non-commercial evaluation. Customer’s use of the Beta Product shall be solely for the purpose of conducting the Beta Evaluation. Customer accepts all risks arising out of the access and use of the Beta Products. Cybersource may, in its sole discretion, at any time, terminate or discontinue the Beta Evaluation. Customer acknowledges and agrees that any Beta Product may still be in development and that Beta Product is provided “AS IS” and may not perform at the level of a commercially available service, may not operate as expected and may be modified prior to release. CYBERSOURCE SHALL NOT BE RESPONSIBLE OR LIABLE UNDER ANY CONTRACT, TORT (INCLUDING NEGLIGENCE), OR OTHERWISE RELATING TO A BETA PRODUCT OR THE BETA EVALUATION (A) FOR LOSS OR INACCURACY OF DATA OR COST OF PROCUREMENT OF SUBSTITUTE GOODS, SERVICES OR TECHNOLOGY, (B) ANY CLAIM, LOSSES, DAMAGES, OR CAUSE OF ACTION ARISING IN CONNECTION WITH THE BETA PRODUCT; OR (C) FOR ANY INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES INCLUDING, BUT NOT LIMITED TO, LOSS OF REVENUES AND LOSS OF PROFITS.
96 changes: 60 additions & 36 deletions Samples/Authentication/SampleCodes/StandAloneHttpSignature.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,70 @@
const superagent = require('superagent');
var path = require('path');
const crypto = require('crypto');
const { faker } = require('@faker-js/faker');
const { write } = require('fs');

var dt = new Date();
var curDate = dt.toGMTString();
/* Create timestamp 8 hours back for report query */
dt.setHours(dt.getHours() - 8);
var requestHost = 'apitest.cybersource.com';
var merchantId = 'testrest';
var merchantKeyId = '08c94330-f618-42a3-b09d-e1e43be5efda';
var merchantSecretKey = 'yBJxy6LjM2TmcPGu+GaJrHtkke25fPpUX+UY6/L/1tE=';
var payload = '{' +
' \"clientReferenceInformation\": {' +
' \"code\": \"TC50171_3\"' +
' },' +
' \"processingInformation\": {' +
' \"commerceIndicator\": \"internet\"' +
' },' +
' \"orderInformation\": {' +
' \"billTo\": {' +
' \"firstName\": \"john\",' +
' \"lastName\": \"doe\",' +
' \"address1\": \"201 S. Division St.\",' +
' \"postalCode\": \"48104-2201\",' +
' \"locality\": \"Ann Arbor\",' +
' \"administrativeArea\": \"MI\",' +
' \"country\": \"US\",' +
' \"phoneNumber\": \"999999999\",' +
' \"email\": \"test@cybs.com\"' +
' },' +
' \"amountDetails\": {' +
' \"totalAmount\": \"10\",' +
' \"currency\": \"USD\"' +
' }' +
' },' +
' \"paymentInformation\": {' +
' \"card\": {' +
' \"expirationYear\": \"2031\",' +
' \"number\": \"5555555555554444\",' +
' \"securityCode\": \"123\",' +
' \"expirationMonth\": \"12\",' +
' \"type\": \"002\"' +
' }' +
' }' +
'}';

function personify(){
var fName = faker.person.firstName();
var lName = faker.person.lastName();
var expYear = dt.getFullYear()+4;
var payload = JSON.stringify({
"clientReferenceInformation" : {
"code" : faker.string.numeric(10)
},
"processingInformation" : {
"capture" : true,
"commerceIndicator" : "internet"
},
"orderInformation" : {
"billTo" : {
"firstName" : fName,
"lastName" : lName,
"address1" : faker.location.streetAddress(),
"postalCode" : faker.location.zipCode(),
"locality" : faker.location.city(),
"administrativeArea" : faker.location.state(),
"country" : "US",
"phoneNumber" : faker.phone.number(),
"email" : faker.internet.email({firstName:fName,lastName:lName})
},
"amountDetails" : {
"totalAmount" : faker.commerce.price({ min: 10, max: 500 }),
"currency" : "USD"
}
},
"paymentInformation" : {
"card" : {
"expirationYear" : expYear,
"number" : faker.finance.creditCardNumber({issuer: '414720#########L'}),
"securityCode" : faker.finance.creditCardCVV(),
"expirationMonth" : "12",
"type" : "001"
}
},
"merchantDefinedInformation" : [
{
"key" : "1",
"value" : merchantId
}
],
"deviceInformation" : {
"fingerprintSessionId" : "",
"ipAddress" : faker.internet.ipv4(),
"useragent" : faker.internet.userAgent()
}
});
return payload;
}
var payload = personify();

function paramToString(param) {
if (param == undefined || param == null) {
Expand Down Expand Up @@ -218,7 +242,7 @@ function processPost(callback) {
}

function processGet(callback) {
var resource = "/reporting/v3/reports?startTime=2021-02-01T00:00:00.0Z&endTime=2021-02-02T23:59:59.0Z&timeQueryType=executedTime&reportMimeType=application/xml";
var resource = "/reporting/v3/reports?startTime="+dt.toISOString()+"&endTime="+(new Date()).toISOString()+"&timeQueryType=executedTime&reportMimeType=application/xml";
var method = "get";
var statusCode = -1;
var url = 'https://' + requestHost + resource;
Expand Down
96 changes: 59 additions & 37 deletions Samples/Authentication/SampleCodes/StandAloneJWT.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,71 @@

const superagent = require('superagent');
const crypto = require('crypto');

const { faker } = require('@faker-js/faker');
var fs = require('fs');
var forge = require('node-forge');
var Jwt = require('jwt-simple');
var path = require('path');

var dt = new Date();
var curDate = dt.toGMTString();
/* Create timestamp 8 hours back for report query */
dt.setHours(dt.getHours() - 8);
var requestHost = "apitest.cybersource.com";
var merchantId = "testrest";
var keyPass = "testrest";
var payload = "{" +
" \"clientReferenceInformation\": {" +
" \"code\": \"TC50171_3\"" +
" }," +
" \"processingInformation\": {" +
" \"commerceIndicator\": \"internet\"" +
" }," +
" \"orderInformation\": {" +
" \"billTo\": {" +
" \"firstName\": \"john\"," +
" \"lastName\": \"doe\"," +
" \"address1\": \"201 S. Division St.\"," +
" \"postalCode\": \"48104-2201\"," +
" \"locality\": \"Ann Arbor\"," +
" \"administrativeArea\": \"MI\"," +
" \"country\": \"US\"," +
" \"phoneNumber\": \"999999999\"," +
" \"email\": \"test@cybs.com\"" +
" }," +
" \"amountDetails\": {" +
" \"totalAmount\": \"10\"," +
" \"currency\": \"USD\"" +
" }" +
" }," +
" \"paymentInformation\": {" +
" \"card\": {" +
" \"expirationYear\": \"2031\"," +
" \"number\": \"5555555555554444\"," +
" \"securityCode\": \"123\"," +
" \"expirationMonth\": \"12\"," +
" \"type\": \"002\"" +
" }" +
" }" +
"}";
function personify(){
var fName = faker.person.firstName();
var lName = faker.person.lastName();
var expYear = dt.getFullYear()+4;
var payload = JSON.stringify({
"clientReferenceInformation" : {
"code" : faker.string.numeric(10)
},
"processingInformation" : {
"capture" : true,
"commerceIndicator" : "internet"
},
"orderInformation" : {
"billTo" : {
"firstName" : fName,
"lastName" : lName,
"address1" : faker.location.streetAddress(),
"postalCode" : faker.location.zipCode(),
"locality" : faker.location.city(),
"administrativeArea" : faker.location.state(),
"country" : "US",
"phoneNumber" : faker.phone.number(),
"email" : faker.internet.email({firstName:fName,lastName:lName})
},
"amountDetails" : {
"totalAmount" : faker.commerce.price({ min: 10, max: 500 }),
"currency" : "USD"
}
},
"paymentInformation" : {
"card" : {
"expirationYear" : expYear,
"number" : faker.finance.creditCardNumber({issuer: '414720#########L'}),
"securityCode" : faker.finance.creditCardCVV(),
"expirationMonth" : "12",
"type" : "001"
}
},
"merchantDefinedInformation" : [
{
"key" : "1",
"value" : merchantId
}
],
"deviceInformation" : {
"fingerprintSessionId" : "",
"ipAddress" : faker.internet.ipv4(),
"useragent" : faker.internet.userAgent()
}
});
return payload;
}
var payload = personify();

function generateDigest(request) {
var buffer = Buffer.from(payload, 'utf8');
Expand Down Expand Up @@ -213,7 +235,7 @@ function processPost(callback) {
}

function processGet(callback) {
var resource = "/reporting/v3/reports?startTime=2021-01-01T00:00:00.0Z&endTime=2021-01-02T23:59:59.0Z&timeQueryType=executedTime&reportMimeType=application/xml";
var resource = "/reporting/v3/reports?startTime="+dt.toISOString()+"&endTime="+(new Date()).toISOString()+"&timeQueryType=executedTime&reportMimeType=application/xml";
var method = "get";
var statusCode = -1;
var url = 'https://' + requestHost + resource;
Expand Down
31 changes: 19 additions & 12 deletions Samples/Authentication/SampleCodes/StandAloneMetaKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var cybersourceRestApi = require('cybersource-rest-client');
var path = require('path');
const { faker } = require('@faker-js/faker');

// common parameters
const AuthenticationType = 'http_signature';
Expand All @@ -23,6 +24,12 @@ const LogDirectory = 'log';
const LogfileMaxSize = '5242880'; //10 MB In Bytes
const EnableMasking = true;

// persona parameters
var dt = new Date();
var expYear = dt.getFullYear()+4;
var fName = faker.person.firstName();
var lName = faker.person.lastName();

function write_log_audit(status) {
var filename = path.basename(__filename).split(".")[0];
console.log(`[Sample Code Testing] [${filename}] ${status}`);
Expand Down Expand Up @@ -65,7 +72,7 @@ function simple_payments_using_meta_key(callback, enable_capture) {
var requestObj = new cybersourceRestApi.CreatePaymentRequest();

var clientReferenceInformation = new cybersourceRestApi.Ptsv2paymentsClientReferenceInformation();
clientReferenceInformation.code = 'TC50171_3';
clientReferenceInformation.code = faker.string.uuid();
requestObj.clientReferenceInformation = clientReferenceInformation;

var processingInformation = new cybersourceRestApi.Ptsv2paymentsProcessingInformation();
Expand All @@ -78,29 +85,29 @@ function simple_payments_using_meta_key(callback, enable_capture) {

var paymentInformation = new cybersourceRestApi.Ptsv2paymentsPaymentInformation();
var paymentInformationCard = new cybersourceRestApi.Ptsv2paymentsPaymentInformationCard();
paymentInformationCard.number = '4111111111111111';
paymentInformationCard.number = faker.finance.creditCardNumber({issuer: '414720#########L'});
paymentInformationCard.expirationMonth = '12';
paymentInformationCard.expirationYear = '2031';
paymentInformationCard.expirationYear = expYear;
paymentInformation.card = paymentInformationCard;

requestObj.paymentInformation = paymentInformation;

var orderInformation = new cybersourceRestApi.Ptsv2paymentsOrderInformation();
var orderInformationAmountDetails = new cybersourceRestApi.Ptsv2paymentsOrderInformationAmountDetails();
orderInformationAmountDetails.totalAmount = '50.00';
orderInformationAmountDetails.totalAmount = faker.commerce.price({ min: 10, max: 500 });
orderInformationAmountDetails.currency = 'USD';
orderInformation.amountDetails = orderInformationAmountDetails;

var orderInformationBillTo = new cybersourceRestApi.Ptsv2paymentsOrderInformationBillTo();
orderInformationBillTo.firstName = 'John';
orderInformationBillTo.lastName = 'Doe';
orderInformationBillTo.address1 = '1 Market St';
orderInformationBillTo.locality = 'san francisco';
orderInformationBillTo.administrativeArea = 'CA';
orderInformationBillTo.postalCode = '94105';
orderInformationBillTo.firstName = fName;
orderInformationBillTo.lastName = lName;
orderInformationBillTo.address1 = faker.location.streetAddress();
orderInformationBillTo.locality = faker.location.city();
orderInformationBillTo.administrativeArea = faker.location.state();
orderInformationBillTo.postalCode = faker.location.zipCode();
orderInformationBillTo.country = 'US';
orderInformationBillTo.email = 'test@cybs.com';
orderInformationBillTo.phoneNumber = '4158880000';
orderInformationBillTo.email = faker.internet.email({firstName:fName,lastName:lName});
orderInformationBillTo.phoneNumber = faker.phone.number();
orderInformation.billTo = orderInformationBillTo;

requestObj.orderInformation = orderInformation;
Expand Down
29 changes: 17 additions & 12 deletions Samples/Authentication/SampleCodes/StandAloneOAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var cybersourceRestApi = require('cybersource-rest-client');
var path = require('path');
const { faker } = require('@faker-js/faker');

function getConfiguration() {

Expand Down Expand Up @@ -37,7 +38,11 @@ function simple_authorization_internet(callback, accessToken, refreshToken) {
var requestObj = new cybersourceRestApi.CreatePaymentRequest();

var clientReferenceInformation = new cybersourceRestApi.Ptsv2paymentsClientReferenceInformation();
clientReferenceInformation.code = 'TC50171_3';
var dt = new Date();
var expYear = dt.getFullYear()+4;
var fName = faker.person.firstName();
var lName = faker.person.lastName();
clientReferenceInformation.code = faker.string.uuid();
requestObj.clientReferenceInformation = clientReferenceInformation;

var processingInformation = new cybersourceRestApi.Ptsv2paymentsProcessingInformation();
Expand All @@ -48,29 +53,29 @@ function simple_authorization_internet(callback, accessToken, refreshToken) {

var paymentInformation = new cybersourceRestApi.Ptsv2paymentsPaymentInformation();
var paymentInformationCard = new cybersourceRestApi.Ptsv2paymentsPaymentInformationCard();
paymentInformationCard.number = '4111111111111111';
paymentInformationCard.number = faker.finance.creditCardNumber({issuer: '414720#########L'});
paymentInformationCard.expirationMonth = '12';
paymentInformationCard.expirationYear = '2031';
paymentInformationCard.expirationYear = expYear;
paymentInformation.card = paymentInformationCard;

requestObj.paymentInformation = paymentInformation;

var orderInformation = new cybersourceRestApi.Ptsv2paymentsOrderInformation();
var orderInformationAmountDetails = new cybersourceRestApi.Ptsv2paymentsOrderInformationAmountDetails();
orderInformationAmountDetails.totalAmount = '50.00';
orderInformationAmountDetails.totalAmount = faker.commerce.price({ min: 10, max: 500 });
orderInformationAmountDetails.currency = 'USD';
orderInformation.amountDetails = orderInformationAmountDetails;

var orderInformationBillTo = new cybersourceRestApi.Ptsv2paymentsOrderInformationBillTo();
orderInformationBillTo.firstName = 'John';
orderInformationBillTo.lastName = 'Doe';
orderInformationBillTo.address1 = '1 Market St';
orderInformationBillTo.locality = 'san francisco';
orderInformationBillTo.administrativeArea = 'CA';
orderInformationBillTo.postalCode = '94105';
orderInformationBillTo.firstName = fName;
orderInformationBillTo.lastName = lName;
orderInformationBillTo.address1 = faker.location.streetAddress();
orderInformationBillTo.locality = faker.location.city();
orderInformationBillTo.administrativeArea = faker.location.state();
orderInformationBillTo.postalCode = faker.location.zipCode();
orderInformationBillTo.country = 'US';
orderInformationBillTo.email = 'test@cybs.com';
orderInformationBillTo.phoneNumber = '4158880000';
orderInformationBillTo.email = faker.internet.email({firstName:fName,lastName:lName});
orderInformationBillTo.phoneNumber = faker.phone.number();
orderInformation.billTo = orderInformationBillTo;

requestObj.orderInformation = orderInformation;
Expand Down
Loading