Skip to content
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

add kount debugging #842

Merged
merged 1 commit into from
Aug 1, 2023
Merged
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
28 changes: 26 additions & 2 deletions lib/recurly/fraud.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const FRAUDNET_PARAMS_ID = 'fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99';

export class Fraud extends Emitter {
constructor (recurly) {
debug('initializing fraud object');
super();
this.recurly = recurly;
this.dataCollectorInitiated = false;
Expand All @@ -35,6 +36,7 @@ export class Fraud extends Emitter {
params (data) {
const { fraud: fraudConfig } = this.recurly.config;
let fraudParams = [];
debug('creating fraud params', data, fraudConfig);

if (fraudConfig.kount.dataCollector && data.fraud_session_id) {
fraudParams.push({
Expand Down Expand Up @@ -83,6 +85,7 @@ export class Fraud extends Emitter {
debug('risk info', error, response);

if (error) {
debug('error detected', error);
if (this.shouldCollectKountData) {
this.emit(
'error',
Expand All @@ -94,43 +97,54 @@ export class Fraud extends Emitter {
}

const { profiles } = response;
debug('preparing to activate profiles', profiles);
this.profiles = profiles;
this.activateProfiles();
},
});
}

activateProfiles () {
if (!this.profiles) return;
if (!this.profiles) {
debug('no profiles available', this.profiles);
return;
}
debug('setting profiles', this.profiles);

this.profiles.forEach((profile) => {
const { processor, params } = profile;

if (processor === 'kount' && this.shouldCollectKountData) {
debug('enabling kount profile', params);
this.activateKountProfile(params);
} else if (processor === 'fraudnet') {
debug('enabling fraudnet profile');
this.activateFraudnetProfile(params);
}
});
}

activateKountProfile (params) {
debug('activating Kount profiles');
const configuredForm = this.recurly.config.fraud.kount.form;
const sessionIdInputElement = dom.createHiddenInput({
'data-recurly': 'fraud_session_id',
value: params.session_id,
'type': 'hidden',
});
debug('kount configured form', configuredForm);

const initialize = () => {
if (!window.ka) {
debug('kount integration failed, no SDK attached');
return this.emit(
'error',
errors('fraud-data-collector-request-failed', {
error: 'Kount SDK failed to load.',
})
);
}
debug('initializing kount SDK');
// eslint-disable-next-line no-undef
const client = new ka.ClientSDK();
client.autoLoadEvents();
Expand All @@ -145,7 +159,9 @@ export class Fraud extends Emitter {
initializerElement.setAttribute('data-event', 'load');

const form = dom.element(configuredForm) || this.getHostedFieldParentForm();

if (form) {
debug('form', form);
const nodes = [
sessionIdInputElement,
scriptElement,
Expand All @@ -154,6 +170,9 @@ export class Fraud extends Emitter {

nodes.forEach((node) => form.appendChild(node));
this.attachedNodes = nodes;
debug('nodes attached', this.attachedNodes, form);
} else {
debug('no form available, kount activation skipped', form);
}

this.emit('ready');
Expand Down Expand Up @@ -196,6 +215,7 @@ export class Fraud extends Emitter {
getHostedFieldParentForm () {
if (this._form) return this._form;
const fields = this.recurly.config.fields;
debug('form fields', fields);
const selectors = Object.keys(fields)
.map((name) => fields[name].selector)
.filter(Boolean);
Expand All @@ -205,7 +225,10 @@ export class Fraud extends Emitter {
window.document.querySelector(selector),
'form'
);
if (dom.element(node)) form = node;
if (dom.element(node)) {
debug('found form', node);
form = node;
}
});

if (form) {
Expand All @@ -214,6 +237,7 @@ export class Fraud extends Emitter {
const missingFormError = errors('fraud-data-collector-missing-form', {
selectors,
});
debug('no form found, emitting error', missingFormError);
this.emit('error', missingFormError);
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/recurly/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,14 @@ export function tokenDispatcher (...args) {
*/
function token (customerData, bus, done) {
debug('token');
debug('customerData', customerData);

const inputs = customerData.values;

if (this.config.parent) {
debug('preparing to create fraud params', this.fraud);
inputs.fraud = this.fraud.params(inputs);
debug('fraud params set', inputs.fraud);
inputs.browser = Risk.browserInfo;

const id = uid();
Expand Down
Loading