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

Remove sending phone number if not present #37

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 13 additions & 12 deletions lib/cardsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,14 @@ instance.interceptors.response.use(
}
)

function checkNullInMetaData(metaData: MetaData) {
const nullIfEmpty = (prop: string | undefined) => {
if (prop === '') {
return undefined
}
return prop
const nullIfEmpty = (prop: string | undefined) => {
if (prop !== undefined && prop.trim() === '') {
return undefined
}
return prop
}

function checkNullInMetaData(metaData: MetaData) {
const updateMetaObj = {
email: nullIfEmpty(metaData.email),
phoneNumber: nullIfEmpty(metaData.phoneNumber),
Expand Down Expand Up @@ -137,9 +138,9 @@ function getCards(pageBefore: string, pageAfter: string, pageSize: string) {
*/
function createCard(payload: CreateCardPayload) {
const url = `/v1/cards`
payload.metadata = checkNullInMetaData(payload.metadata)

return instance.post(url, payload)
const modifiedPayload = Object.assign({}, payload)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this fixes the issue. Try to use payload:

 {
    email: 'my-email@xyz.com',
    phoneNumber: '+491777777',
    sessionId: 'xyz',
    ipAddress: '10.0.2.1',
    newProp: 'my-prop'
  }

newProp will be omitted. That's why I suggested the spread syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for not understanding the previous comment. I have updated the code now

modifiedPayload.metadata = checkNullInMetaData(modifiedPayload.metadata)
return instance.post(url, modifiedPayload)
}

/**
Expand All @@ -150,9 +151,9 @@ function createCard(payload: CreateCardPayload) {
*/
function updateCard(cardId: string, payload: UpdateCardPayload) {
const url = `/v1/cards/${cardId}`
payload.metadata = checkNullInMetaData(payload.metadata)

return instance.put(url, payload)
const modifiedPayload = Object.assign({}, payload)
modifiedPayload.metadata = checkNullInMetaData(modifiedPayload.metadata)
return instance.post(url, modifiedPayload)
}

export default {
Expand Down
5 changes: 3 additions & 2 deletions lib/marketplaceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ function getInstance() {
*/
function createPayment(payload: CreateMarketplacePaymentPayload) {
const url = `/v1/marketplace/payments`
payload.metadata = checkNullInMetaData(payload.metadata)
return instance.post(url, payload)
const modifiedPayload = Object.assign({}, payload)
modifiedPayload.metadata = checkNullInMetaData(modifiedPayload.metadata)
return instance.post(url, modifiedPayload)
}

/**
Expand Down
25 changes: 10 additions & 15 deletions lib/paymentsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ instance.interceptors.response.use(
}
)

function checkNullInMetaData(metaData: MetaData) {
const nullIfEmpty = (prop: string | undefined) => {
if (prop === '') {
return undefined
}
return prop
const nullIfEmpty = (prop: string | undefined) => {
if (prop === '') {
return undefined
}
return prop
}

function checkNullInMetaData(metaData: MetaData) {
const updateMetaObj = {
email: metaData.email,
phoneNumber: nullIfEmpty(metaData.phoneNumber),
Expand Down Expand Up @@ -107,8 +108,9 @@ function cancelPayment(id: string, payload: any) {
*/
function createPayment(payload: CreatePaymentPayload) {
const url = `/v1/payments`
payload.metadata = checkNullInMetaData(payload.metadata)
return instance.post(url, payload)
const modifiedPayload = Object.assign({}, payload)
modifiedPayload.metadata = checkNullInMetaData(modifiedPayload.metadata)
return instance.post(url, modifiedPayload)
}

/**
Expand All @@ -126,13 +128,6 @@ function getPayments(
pageAfter: string,
pageSize: string
) {
const nullIfEmpty = (prop: string) => {
if (prop === '') {
return null
}
return prop
}

const queryParams = {
from: nullIfEmpty(from),
to: nullIfEmpty(to),
Expand Down