Skip to content

Commit

Permalink
Update the params for create wire account API (#57)
Browse files Browse the repository at this point in the history
* Update the params for create wire account API

* Adding test data

* Updating the address

* Updating the test account data and fix vue error
  • Loading branch information
tarunkumar2 authored Jun 25, 2020
1 parent 305f924 commit bbf4f0c
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 6 deletions.
21 changes: 17 additions & 4 deletions lib/wiresApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { getAPIHostname } from './apiTarget'

export interface CreateWireAccountPayload {
idempotencyKey: string
beneficiaryName: string
bankName: string
accountNumber: string
bankIdentifier: string
beneficiaryName: string | undefined
bankName: string | undefined
accountNumber: string | undefined
bankIdentifier: string | undefined
iban: string | undefined
billingDetails: {
name: string
city: string
Expand Down Expand Up @@ -58,12 +59,24 @@ function getInstance() {
return instance
}

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

/**
* Create Wire Account
* @param {*} payload (contains form data)
*/
function createWireAccount(payload: CreateWireAccountPayload) {
const url = '/v1/wires'
payload.beneficiaryName = nullIfEmpty(payload.beneficiaryName)
payload.bankName = nullIfEmpty(payload.bankName)
payload.accountNumber = nullIfEmpty(payload.accountNumber)
payload.bankIdentifier = nullIfEmpty(payload.bankIdentifier)
payload.iban = nullIfEmpty(payload.iban)
return instance.post(url, payload)
}

Expand Down
57 changes: 56 additions & 1 deletion lib/wiresTestData.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export const exampleWireAccounts = [
{
title: 'Test Data',
title: 'US Bank Account',
formData: {
beneficiaryName: 'Satoshi Nakamoto',
bankName: 'WELLS FARGO BANK',
accountNumber: '11111111111',
bankIdentifier: '121000248',
iban: '',
billingDetails: {
name: 'Satoshi Nakamoto',
city: 'Boston',
Expand All @@ -25,4 +26,58 @@ export const exampleWireAccounts = [
},
},
},
{
title: 'German Bank Account',
formData: {
beneficiaryName: 'Satoshi Nakamoto',
bankName: 'COMMERZBANK',
accountNumber: '',
bankIdentifier: '',
iban: 'DE31100400480532013000',
billingDetails: {
name: 'Satoshi Nakamoto',
city: 'Boston',
country: 'US',
line1: '100 Money Street',
line2: 'Suite 1',
district: 'MA',
postalCode: '01234',
},
bankAddress: {
city: 'Kassel',
country: 'DE',
line1: 'Königspl 32 - 34',
line2: '',
district: 'Kassel',
postalCode: '34117',
},
},
},
{
title: 'Mexican Bank Account',
formData: {
beneficiaryName: 'Satoshi Nakamoto',
bankName: 'Banco Nacional de México',
accountNumber: '002010077777777771',
bankIdentifier: '',
iban: '',
billingDetails: {
name: 'Satoshi Nakamoto',
city: 'Boston',
country: 'US',
line1: '100 Money Street',
line2: 'Suite 1',
district: 'MA',
postalCode: '01234',
},
bankAddress: {
city: 'México DF',
country: 'MX',
line1: 'Isabel la Católica 165',
line2: 'Colonia Obrera',
district: 'México DF',
postalCode: '06800',
},
},
},
]
41 changes: 40 additions & 1 deletion pages/debug/wires/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
<v-text-field
v-model="formData.bankIdentifier"
label="Bank Identifier"
hint="RTN/BIC/Swift code of the bank associated with the account. Required for US accounts"
/>

<v-text-field
v-model="formData.iban"
label="IBAN"
hint="Required for accounts outside of the US"
/>

<v-text-field
Expand Down Expand Up @@ -167,6 +174,7 @@ export default class CreateCardClass extends Vue {
bankName: '',
accountNumber: '',
bankIdentifier: '',
iban: '',
billingDetails: {
name: '',
city: '',
Expand Down Expand Up @@ -213,9 +221,40 @@ export default class CreateCardClass extends Vue {
async makeApiCall() {
this.loading = true
const {
beneficiaryName,
bankName,
accountNumber,
bankIdentifier,
iban,
...data
} = this.formData
const { billingDetails, bankAddress } = data
const payload: CreateWireAccountPayload = {
idempotencyKey: uuidv4(),
...this.formData,
beneficiaryName,
bankName,
accountNumber,
bankIdentifier,
iban,
billingDetails: {
name: billingDetails.name,
line1: billingDetails.line1,
line2: billingDetails.line2,
city: billingDetails.city,
district: billingDetails.district,
country: billingDetails.country,
postalCode: billingDetails.postalCode,
},
bankAddress: {
line1: bankAddress.line1,
line2: bankAddress.line2,
city: bankAddress.city,
district: bankAddress.district,
country: bankAddress.country,
postalCode: bankAddress.postalCode,
},
}
try {
await this.$wiresApi.createWireAccount(payload)
Expand Down

0 comments on commit bbf4f0c

Please sign in to comment.