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

feat: add partner's api's #351

Merged
merged 13 commits into from
Jun 30, 2023
15 changes: 8 additions & 7 deletions lib/resources/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@ module.exports = function (api) {

return {
create(params, callback) {
let { notes, ...rest } = params
let data = Object.assign(rest, normalizeNotes(notes));
Copy link

@1995navinkumar 1995navinkumar Jun 22, 2023

Choose a reason for hiding this comment

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

What does this normalizeNotes do? I saw the implementation, it just adds notes to every key? The curl request didn't have this in req body.

var data = { "phone": "9000090000" } ; 
// gets converted to
var normalised = { "notes[phone]" : "9000090000" } ;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@1995navinkumar i had checked this one, but notes are not working without normalizeNotes.

sending notes without normalizeNotes , its throw error

Screenshot 2023-06-26 at 10 39 27 AM

sending notes with normalizeNotes.

Screenshot 2023-06-26 at 10 40 40 AM

Choose a reason for hiding this comment

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

@ankitdas13 How did you test this? Using a test account? Also, can you share the request payload before and after normalizeNotes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@1995navinkumar Yes, I have a test key, instead of creating a new object by Object.assign, I pass the params to data and it's working without normalizeNotes

create(params, callback) {
    return api.post({
        version: 'v2',
        url: `${BASE_URL}`,
        data: params
    }, callback);
},

payload

{
  url: '/v2/accounts',
  form: {
    email: '[email protected]',
    phone: '9000090000',
    legal_business_name: 'Acme Corp',
    business_type: 'partnership',
    customer_facing_business_name: 'Example',
    profile: {
      category: 'healthcare',
      subcategory: 'clinic',
      description: 'Healthcare E-commerce platform',
      addresses: [Object],
      business_model: 'Online Clothing ( men, women, ethnic, modern ) fashion and lifestyle, accessories, t-shirt, shirt, track pant, shoes.'
    },
    legal_info: { pan: 'AAACL1234C', gst: '18AABCU9603R1ZM' },
    brand: { color: 'FFFFFF' },
    notes: { internal_ref_id: '123123' },
    contact_name: 'Gaurav Kumar',
    contact_info: { chargeback: [Object], refund: [Object], support: [Object] },
    apps: { websites: [Array], android: [Array], ios: [Array] }
  }
}

Should I remove the normalizeNotes from other methods after testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@1995navinkumar reverted previous changes except client validation


return api.post({
version: 'v2',
url: `${BASE_URL}`,
data: params
data: data
}, callback);
},

edit(accountId, params, callback) {
let { notes, ...rest } = params
let data = Object.assign(rest, normalizeNotes(notes));

return api.patch({
version: 'v2',
url: `${BASE_URL}/${accountId}`,
data: params
data: data
}, callback);
},

Expand All @@ -38,11 +44,6 @@ module.exports = function (api) {
},

uploadAccountDoc(accountId, params, callback) {

if (!accountId) {
return Promise.reject("Account Id is mandatroy");
}

return api.post({
version: 'v2',
url: `${BASE_URL}/${accountId}/documents`,
Expand Down
8 changes: 4 additions & 4 deletions lib/resources/stakeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = function (api) {
return {
create(accountId, params, callback) {

let { relationship, ...rest } = params
let { relationship, notes, ...rest } = params

if(params.hasOwnProperty('relationship')){
if(params.relationship.hasOwnProperty('executive')){
Expand All @@ -21,7 +21,7 @@ module.exports = function (api) {
}
}

let data = Object.assign({relationship: relationship}, rest);
let data = Object.assign({relationship: relationship}, normalizeNotes(notes), rest);

return api.post({
version: 'v2',
Expand All @@ -31,7 +31,7 @@ module.exports = function (api) {
},

edit(accountId, stakeholderId, params, callback) {
let { relationship, ...rest } = params
let { notes, relationship, ...rest } = params

if(params.hasOwnProperty('relationship')){
if(params.relationship.hasOwnProperty('executive')){
Expand All @@ -43,7 +43,7 @@ module.exports = function (api) {
}
}

let data = Object.assign({relationship: relationship}, rest);
let data = Object.assign({relationship: relationship}, normalizeNotes(notes), rest);

return api.patch({
version: 'v2',
Expand Down
12 changes: 11 additions & 1 deletion lib/types/accounts.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IMap, INormalizeError, PartialOptional, RazorpayPaginationOptions } from "./api";
import * as fs from 'fs';

export declare namespace Accounts {
interface RazorpayAccountBaseRequestBody {
Expand Down Expand Up @@ -217,7 +218,16 @@ export declare namespace Accounts {
created_at: number;
}

interface FileCreateParams {}
interface FileCreateParams {
file: {
value: fs.ReadStream;
options: {
filename: string;
contentType: string | null;
};
};
document_type: string;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@1995navinkumar added form-data params type check for document upload api

interface RazorpayAccountDocuments {
business_proof_of_identification: [
Expand Down
14 changes: 12 additions & 2 deletions lib/types/stakeholders.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Accounts } from "./accounts";
import { IMap, INormalizeError, PartialOptional, RazorpayPaginationOptions } from "./api";
import * as fs from "fs";

export declare namespace Stakeholders {
interface RazorpayStakeholderBaseRequestBody {
Expand Down Expand Up @@ -47,7 +48,7 @@ export declare namespace Stakeholders {

interface RazorpayStakeholderCreateRequestBody extends RazorpayStakeholderBaseRequestBody { }

interface RazorpayStakeholderUpdateRequestBody extends Omit<RazorpayStakeholderBaseRequestBody, 'email'> { }
interface RazorpayStakeholderUpdateRequestBody extends Partial<Omit<RazorpayStakeholderBaseRequestBody, 'email'>> { }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@1995navinkumar added partial because all params is optional , also checked with empty objects as well in postmen.

for your reference


interface RazorpayStakeholder extends RazorpayStakeholderBaseRequestBody {
/**
Expand Down Expand Up @@ -86,7 +87,16 @@ export declare namespace Stakeholders {
director?: boolean;
}

interface FileCreateParams {}
interface FileCreateParams {
file: {
value: fs.ReadStream;
options: {
filename: string;
contentType: string | null;
};
};
document_type: string;
}

interface RazorpayStakeholderDocuments {
individual_proof_of_address: [
Expand Down