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

Add pay-link methods #75

Merged
merged 2 commits into from
Nov 15, 2023
Merged
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
40 changes: 40 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ This is an Node.JS client for the [Moneyhub API](https://docs.moneyhubenterprise
- Generate authorisation url for payments
- Add Payees
- Get Payees and payments
- Add Pay links
- Get Pay links
- Get categories
- CRUD actions on projects
- CRUD actions on transaction attachments
Expand Down Expand Up @@ -1561,6 +1563,44 @@ const paymentData = await moneyhub.getPaymentFromIDToken({
});
```

#### `addPayLink`

Create a pay-link for dynamically created party-to-party payments using your custom themed widget. This function uses the scope `pay_link:create`. You will receive back the pay-link details as well as the pay-link id in the response. With that id you can then render the widget i.e. https://identity.moneyhub.co.uk/widget-pages/widget-id#payLinkId=pay-link-id

```javascript
const paymentData = await moneyhub.addPayLink({
widgetId: "Id of the pay-link widget used to render the payment" // required
payee: "Details of payee to create", // required or payeeId
payerId: "Id of payer", // required or payee
amount: "Amount in pence to authorize payment", // required
expiry: "ISO Date-time string for pay-link expiry"
reference: "Payee reference", // required
});
```

#### `getPayLink`

Get a single pay-link by its id. This function uses the scope `pay_link:read`.

```javascript
const paymentData = await moneyhub.getPayLink({
id: "Id of the pay-link"
});
```

#### `getPayLinks`

This method returns a list of created pay-links. This function uses the scope `pay_link:read`

```javascript
const payments = await moneyhub.getPayLinks({
limit: "limit", // optional
offset: "offset", // optional
payeeId: "payee-id", // optional
widgetId: "widget-id", // optional
});
```

### Standing Orders

#### `getStandingOrderAuthorizeUrl`
Expand Down
2 changes: 2 additions & 0 deletions src/requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import notificationThresholds from "./notification-thresholds"
import osip from "./osip"
import payees from "./payees"
import payments from "./payments"
import payLinks from "./pay-links"
import projects from "./projects"
import recurringPayments from "./recurring-payments"
import regularTransactions from "./regular-transactions"
Expand Down Expand Up @@ -36,6 +37,7 @@ export default ({config, request}: RequestsParams) => {
...osip({config, request}),
...payees({config, request}),
...payments({config, request}),
...payLinks({config, request}),
...projects({config, request}),
...recurringPayments({config, request}),
...regularTransactions({config, request}),
Expand Down
53 changes: 53 additions & 0 deletions src/requests/pay-links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {ApiResponse, ExtraOptions, RequestsParams} from "../request"
import {
PayLinksRequests,
AddPayLink,
GetPayLink,
GetPayLinks,
} from "./types/pay-links"
import {PayLink} from "../schema/pay-link"

export default ({config, request}: RequestsParams): PayLinksRequests => {
const {identityServiceUrl} = config

const addPayLink: AddPayLink = (
body,
options?: ExtraOptions,
): Promise<ApiResponse<PayLink>> =>
request(`${identityServiceUrl}/pay-links`, {
method: "POST",
body,
cc: {
scope: "pay_link:create",
},
options,
})
const getPayLink: GetPayLink = (
{id},
options?: ExtraOptions,
): Promise<ApiResponse<PayLink>> =>
request(`${identityServiceUrl}/pay-links/${id}`, {
cc: {
scope: "pay_link:read",
},
options,
})

const getPayLinks: GetPayLinks = (
params = {},
options,
): Promise<ApiResponse<PayLink[]>> =>
request(`${identityServiceUrl}/pay-links`, {
searchParams: params,
cc: {
scope: "pay_link:read",
},
options,
})

return {
addPayLink,
getPayLink,
getPayLinks,
}
}
31 changes: 31 additions & 0 deletions src/requests/types/pay-links.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {ApiResponse, ExtraOptions} from "../../request"
import {RequestPayee} from "../../schema/payee"
import {PayLink, PayLinkSearchParams} from "../../schema/pay-link"

export type AddPayLink = (
body: {
widgetId: string
payeeId?: string
amount?: number
payee?: RequestPayee
reference: string
expiry?: string
},
options?: ExtraOptions,
) => Promise<ApiResponse<PayLink>>

export type GetPayLink = (
{id}: {id: string},
options?: ExtraOptions,
) => Promise<ApiResponse<PayLink>>

export type GetPayLinks = (
params?: PayLinkSearchParams,
options?: ExtraOptions,
) => Promise<ApiResponse<PayLink[]>>

export interface PayLinksRequests {
addPayLink: AddPayLink
getPayLink: GetPayLink
getPayLinks: GetPayLinks
}
19 changes: 19 additions & 0 deletions src/schema/pay-link.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {SearchParams} from "../request"

export interface PayLinkSearchParams extends SearchParams {
widgetId?: string
payeeId?: string
}

export interface PayLink {
id: string
clientId: string
payeeId: string
reference: string
widgetId: string
amount?: number
expiry?: string
endToEndId?: string
createdAt: string
updatedAt: string
}
Loading