Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,6 @@ typings/

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

/dist
.idea
2 changes: 1 addition & 1 deletion src/services/paymentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface PaymentCreateRequest {
// Amount, in the lowest denomination for the currency (e.g. pence in GBP, cents
// in EUR).

amount: string;
amount: number;

// The amount to be deducted from the payment as the OAuth app's fee, in the
// lowest denomination for the currency (e.g. pence in GBP, cents in EUR).
Expand Down
2 changes: 1 addition & 1 deletion src/types/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ export enum PayerAuthorisationStatus {
export interface Payment {
// Amount, in the lowest denomination for the currency (e.g. pence in GBP,
// cents in EUR).
amount: string;
amount: number;

// Amount [refunded](#core-endpoints-refunds), in the lowest denomination for
// the currency (e.g. pence in GBP, cents in EUR).
Expand Down
20 changes: 10 additions & 10 deletions src/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* is genuinely from GoCardless, and secondly it parses each `event` object in the
* JSON object into an `GoCardless.Event` class.
*/

const cryptoJS = require('crypto-js');
const safeCompare = require('buffer-equal-constant-time');
import cryptoJS from 'crypto-js';
import safeCompare from 'buffer-equal-constant-time';
import type {Event} from './types/Types';

function InvalidSignatureError() {
this.message =
Expand All @@ -29,11 +29,10 @@ function InvalidSignatureError() {
* @signatureHeader [string]: The signature included in the webhook request, as specified
* by the `Webhook-Signature` header.
*/
function parse(body, webhookSecret, signatureHeader) {
function parse(body: string, webhookSecret: string, signatureHeader: string) {
verifySignature(body, webhookSecret, signatureHeader);

const eventsData = JSON.parse(body)['events'];
return eventsData.map(eventJson => eventJson);
return JSON.parse(body)['events'] as Event[];
}

/**
Expand All @@ -46,7 +45,7 @@ function parse(body, webhookSecret, signatureHeader) {
* @signatureHeader [string]: The signature included in the webhook request, as specified
* by the `Webhook-Signature` header.
*/
function verifySignature(body, webhookSecret, signatureHeader) {
function verifySignature(body:string, webhookSecret:string, signatureHeader:string) {
const rawDigest = cryptoJS.HmacSHA256(body, webhookSecret);

const bufferDigest = Buffer.from(rawDigest.toString(cryptoJS.enc.Hex));
Expand All @@ -57,7 +56,8 @@ function verifySignature(body, webhookSecret, signatureHeader) {
}
}

module.exports = {
export {
parse,
InvalidSignatureError,
Copy link

Choose a reason for hiding this comment

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

Hi! Why is this error not being retured anymore?
Thanks 🙂

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I don't know why GitHub didn't notify me about your reply 🤦‍♂️

That's a good question (I would have probably a better response three weeks ago), but from what I see I probably thought that it was a mistake (because we would want to export the verifySignature instead of InvalidSignatureError). But if you want to check the error instance somewhere I guess you need that.

I can re-add it back

Copy link
Author

Choose a reason for hiding this comment

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

@dreinon Done,

Sorry for the late response, I'll double check my github settings 🤦‍♂️

Copy link

Choose a reason for hiding this comment

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

Thanks! No worries! We can't do much until the gocardless team replies back haha

Copy link
Author

Choose a reason for hiding this comment

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

Damn I thought you were on the gocardless team 😭

Copy link

Choose a reason for hiding this comment

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

Unfortunately not :(

};
verifySignature,
InvalidSignatureError
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "Node",
Copy link
Author

Choose a reason for hiding this comment

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

Also forgot: this was duplicated

"newLine": "lf",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
Expand Down