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

DPK-2958 Support V20201031 in Customer Object SDK #205

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
coverage
.vscode/
.idea
.tool-versions
36 changes: 36 additions & 0 deletions examples/with_async/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,39 @@ const c = new Customer({});
process.exit(1);
}
})();

(async function() {
try {
let customer = await c.createCustomer({
referenceID: new Date().toISOString(),
type: 'INDIVIDUAL',
individualDetail: {
givenNames: 'customer 1',
surname: 'surname',
},
email: '[email protected]',
mobileNumber: '+6281212345678',
description: 'dummy customer',
addresses: [],
apiVersion: '2020-10-31',
});
console.log('created customer', customer); // eslint-disable-line no-console

customer = await c.getCustomer({
id: customer.id,
apiVersion: '2020-10-31',
});
// eslint-disable-next-line no-console
console.log('retrieved customer', customer);

const customers = await c.getCustomerByReferenceID({
referenceID: customer.reference_id,
apiVersion: '2020-10-31',
});
// eslint-disable-next-line no-console
console.log('retrieved customers', customers);
} catch (e) {
console.error(e); // eslint-disable-line no-console
process.exit(1);
}
})();
37 changes: 37 additions & 0 deletions examples/with_promises/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,40 @@ c.createCustomer({
console.error(e); // eslint-disable-line no-console
process.exit(1);
});

c.createCustomer({
referenceID: new Date().toISOString(),
type: 'INDIVIDUAL',
individualDetail: {
givenNames: 'customer 1',
surname: 'surname',
},
email: '[email protected]',
mobileNumber: '+6281212345678',
description: 'dummy customer',
addresses: [],
apiVersion: '2020-10-31',
})
.then(r => {
console.log('created customer', r); // eslint-disable-line no-console
return r;
})
.then(r => c.getCustomer({ id: r.id, apiVersion: '2020-10-31' }))
.then(r => {
console.log('retrieved customer', r); // eslint-disable-line no-console
return r;
})
.then(r =>
c.getCustomerByReferenceID({
referenceID: r.reference_id,
apiVersion: '2020-10-31',
}),
)
.then(r => {
console.log('retrieved customers', r); // eslint-disable-line no-console
return r[0];
})
.catch(e => {
console.error(e); // eslint-disable-line no-console
process.exit(1);
});
37 changes: 37 additions & 0 deletions integration_test/customer_v20201031.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const x = require('./xendit.test');

const { Customer } = x;
const c = new Customer({});

module.exports = function() {
return c
.createCustomer({
referenceID: new Date().toISOString(),
type: 'INDIVIDUAL',
individualDetail: {
givenNames: 'customer 1',
surname: 'surname',
},
email: '[email protected]',
mobileNumber: '+6281212345678',
description: 'dummy customer',
addresses: [],
apiVersion: '2020-10-31',
})
.then(r => c.getCustomer({ id: r.id, apiVersion: '2020-10-31' }))
.then(r =>
c.getCustomerByReferenceID({
referenceID: r.reference_id,
apiVersion: '2020-10-31',
}),
)
.then(() => {
// eslint-disable-next-line no-console
console.log('Customer integration test done...');
})
.catch(e => {
throw new Error(
`Customer integration tests failed with error: ${e.message}`,
);
});
};
3 changes: 2 additions & 1 deletion integration_test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Promise.all([
require('./qr_code.test')(),
require('./platform.test')(),
require('./regional_retail_outlet.test'),
require('./customer.test')(),
require('./customer_v20200519.test')(),
require('./customer_v20201031.test')(),
require('./direct_debit.test')(),
require('./report.test')(),
require('./transaction.test')(),
Expand Down
75 changes: 74 additions & 1 deletion src/customer/customer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,52 @@ interface Address {
postalCode?: string;
}

interface IdentityAccount {
type: string;
company?: string;
description?: string;
country?: string;
properties?: object;
}

interface BusinessDetail {
businessName: string;
businessType?: string;
natureOfBusiness?: string;
businessDomicile?: string;
dateOfRegistration?: string;
tradingName?: string;
}

interface Employment {
employerName?: string;
natureOfBusiness?: string;
roleDescription?: string;
}

interface IndividualDetail {
givenNames: string;
givenNamesNonRoman?: string;
surname?: string;
surnameNonRoman?: string;
nationality?: string;
placeOfBirth?: string;
dateOfBirth?: Date;
gender?: string;
employment?: Employment;
}

interface KYCDocument {
country: string;
type: string;
subType?: string;
documentName?: string;
documentNumber?: string;
expiresAt?: Date;
holderName?: string;
documentImages?: string[];
}

export = class Customer {
constructor({});
static _constructorWithInjectedXenditOpts: (
Expand All @@ -19,7 +65,7 @@ export = class Customer {
referenceID: string;
mobileNumber?: string;
email?: string;
givenNames: string;
givenNames?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this field be mandatory?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for v20200519, yes it's mandatory
but for v20201031, we don't have that field anymore, it will be under individualDetail

middleName?: string;
surname?: string;
description?: string;
Expand All @@ -29,6 +75,20 @@ export = class Customer {
dateOfBirth?: string;
metadata?: object;
apiVersion?: string;
type?: string;
individualDetail?: IndividualDetail;
businessDetail?: BusinessDetail;
phoneNumber?: string;
hashedPhoneNumber?: string;
identityAccounts?: IdentityAccount[];
kycDocuments?: KYCDocument[];
description?: string;
dateOfRegistration?: Date;
domicileOfRegistration?: string;
entity?: string;
client?: string;
clientName?: string;
metadata?: object;
}): Promise<object>;
getCustomer(data: { id: string; apiVersion?: string }): Promise<object>;
getCustomerByReferenceID(data: {
Expand All @@ -49,5 +109,18 @@ export = class Customer {
dateOfBirth?: string;
metadata?: object;
apiVersion?: string;
type?: string;
individualDetail?: IndividualDetail;
businessDetail?: BusinessDetail;
phoneNumber?: string;
hashedPhoneNumber?: string;
identityAccounts?: IdentityAccount[];
kycDocuments?: KYCDocument[];
description?: string;
dateOfRegistration?: Date;
domicileOfRegistration?: string;
entity?: string;
client?: string;
clientName?: string;
}): Promise<object>;
};
Loading
Loading