Skip to content

Commit

Permalink
Merge pull request #100 from coby9241/chore/add-get-charge-for-user-id
Browse files Browse the repository at this point in the history
chore(card): add for-user-id support to get charge
  • Loading branch information
stanleynguyen authored Jul 21, 2021
2 parents 61180e3 + c258286 commit f7f9a5e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ card.captureCharge(data: {
#### Get charge

```ts
card.getCharge(data: { chargeID: string })
card.getCharge(data: { chargeID: string; forUserID?: string })
```

#### Create authorization
Expand Down
5 changes: 4 additions & 1 deletion src/card/charge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ export function captureCharge(data: {
forUserID?: string;
}): Promise<object>;

export function getCharge(data: { chargeID: string }): Promise<object>;
export function getCharge(data: {
chargeID: string;
forUserID?: string;
}): Promise<object>;
11 changes: 10 additions & 1 deletion src/card/charge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f7f9a5e

Please sign in to comment.