From 8cdca356875244797333726a3d1b5675828fba41 Mon Sep 17 00:00:00 2001 From: coby9241 Date: Wed, 21 Jul 2021 12:41:31 +0800 Subject: [PATCH 1/2] chore(card): add for-user-id support to get charge --- src/card/charge.d.ts | 5 ++++- src/card/charge.js | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/card/charge.d.ts b/src/card/charge.d.ts index a067197..5607933 100644 --- a/src/card/charge.d.ts +++ b/src/card/charge.d.ts @@ -20,4 +20,7 @@ export function captureCharge(data: { forUserID?: string; }): Promise; -export function getCharge(data: { chargeID: string }): Promise; +export function getCharge(data: { + chargeID: string; + forUserID?: string; +}): Promise; diff --git a/src/card/charge.js b/src/card/charge.js index e7bbc15..8a011c9 100644 --- a/src/card/charge.js +++ b/src/card/charge.js @@ -69,11 +69,20 @@ function getCharge(data) { const compulsoryFields = ['chargeID']; Validate.rejectOnMissingFields(compulsoryFields, data, reject); + let headers = { + Authorization: Auth.basicAuthHeader(this.opts.secretKey), + 'Content-Type': 'application/json', + }; + + if (data && data.forUserID) { + headers['for-user-id'] = data.forUserID; + } + fetchWithHTTPErr( `${this.API_ENDPOINT}/credit_card_charges/${data.chargeID}`, { method: 'GET', - headers: { Authorization: Auth.basicAuthHeader(this.opts.secretKey) }, + headers, }, ) .then(resolve) From c25828643eae71ed73d1f1d2aabaf6c8f93b4244 Mon Sep 17 00:00:00 2001 From: coby9241 Date: Wed, 21 Jul 2021 12:50:13 +0800 Subject: [PATCH 2/2] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a570c4d..4f347fe 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ card.captureCharge(data: { #### Get charge ```ts -card.getCharge(data: { chargeID: string }) +card.getCharge(data: { chargeID: string; forUserID?: string }) ``` #### Create authorization