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

Customer Redeemables #266

Closed
wants to merge 6 commits into from
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
5 changes: 5 additions & 0 deletions .changeset/hungry-roses-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@voucherify/sdk': patch
---

New endpoint support - `customer-redeemable`
7 changes: 7 additions & 0 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ Methods are provided within `client.customers.*` namespace.
- [Update Customers in bulk](#update-customers-in-bulk)
- [Update Customers' Metadata in bulk](#update-customers-metadata-in-bulk)
- [Import and Update Customers using CSV](#import-and-update-customers-using-csv)
- [List Redeemables](#list-redeemables)

#### [Create Customer](https://docs.voucherify.io/reference/create-customer)

Expand Down Expand Up @@ -759,6 +760,12 @@ client.customers.updateInBulk(customers)
client.customers.updateMetadataInBulk(sourceIdsAndMetadata)
```

#### [List Redeemables](https://docs.voucherify.io/reference/list-customer-redeemables)

```javascript
client.customers.listRedeemables(id, params)
```

---

### Consents
Expand Down
7 changes: 7 additions & 0 deletions packages/sdk/src/Customers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ class Customers {

return this.client.post<AAT.AsyncActionCreateResponse>(`/customers/importCSV`, form, undefined, headers)
}

/**
* @see https://docs.voucherify.io/reference/list-customer-redeemables
*/
public listRedeemables(id: string, params?: T.CustomerRedeemablesListQueryParams) {
return this.client.get<T.CustomerRedeemablesListResponse>(`/customers/${encode(id)}/redeemables`, params)
}
}

export { Customers }
36 changes: 36 additions & 0 deletions packages/sdk/src/types/Customers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Legacy code
import { VouchersResponse } from './Vouchers'

export interface SimpleCustomer {
id: string
name?: string
Expand Down Expand Up @@ -121,6 +123,40 @@ export interface CustomerActivitiesListResponse {
data: Record<string, any>[]
}

export interface CustomerRedeemablesListQueryParams {
limit?: number
page?: number
order?: 'created_at' | '-created_at' | 'id' | '-id'
starting_after_id?: string
filters?: Record<string, any>
}

export interface CustomerRedeemablesListResponse {
object: 'list'
total: number
data_ref: 'data'
data: Record<string, CustomerRedeemable>[]
}

export interface CustomerRedeemable {
id: string
created_at: string
redeemable_id: string
redeemable_object: string
customer_id: string
holder_role: 'OWNER' | 'REFERRER' | 'REFEREE'
campaign_id: string
campaign_type: 'LOYALTY_PROGRAM' | 'PROMOTION' | 'DISCOUNT_COUPONS' | 'GIFT_VOUCHERS' | 'REFERRAL_PROGRAM'
voucher_type: 'GIFT' | 'DISCOUNT' | 'LOYALTY_CARD' | 'LUCKY_DRAW'
redeemable: Redeemable
}

export interface Redeemable {
type: string
voucher: VouchersResponse
status: 'ACTIVE' | 'USED' | 'DISABLED' | 'NOT_ACTIVE' | 'EXPIRED' | 'NO_BALANCE'
}

export type CustomersCreateBody = CustomerRequest
export type CustomersCreateResponse = CustomerObject | CustomerUnconfirmed

Expand Down
31 changes: 31 additions & 0 deletions packages/sdk/test/customers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { voucherifyClient as client } from './client'
import { generateRandomString } from './utils/generateRandomString'
import { generateCustomerCSV } from './utils/generateCustomerCSV'
import { CustomerRequest, DiscountVouchersTypesEnum, DistributionsPublicationsCreateParams } from '@voucherify/sdk'

jest.setTimeout(15000)

Expand Down Expand Up @@ -173,4 +174,34 @@ describe('Customers API', () => {
}
expect(updatedCustomerWithNoAddress.address).toEqual(removedAddress)
})

it('Should return redeemable for customer', async () => {
const createdCustomer: CustomerRequest = await client.customers.create({ source_id: generateRandomString() })

const discountCampaign = await client.campaigns.create({
campaign_type: 'DISCOUNT_COUPONS',
name: generateRandomString(),
type: 'AUTO_UPDATE',
voucher: {
code_config: {
length: 3,
},
type: 'DISCOUNT_VOUCHER',
discount: {
amount_off: 0,
type: DiscountVouchersTypesEnum.AMOUNT,
},
},
})

const distributionsPublicationsCreateParams: DistributionsPublicationsCreateParams = {
customer: createdCustomer,
campaign: discountCampaign,
}

await client.distributions.publications.create(distributionsPublicationsCreateParams)

const redeemables = await client.customers.listRedeemables(createdCustomer.id as string)
expect(redeemables.data).toBeDefined()
})
})
Loading