Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

new redeem stackable object type #285

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

patryksmolarz
Copy link

WHAT

The new RedemptionsRedeemStackableRedemptionResult object type, which is separated from the RedemptionsRedeemResponse type as a redeem-voucher method is deprecated.

In connection with this change RedemptionsRedeemStackableRedemptionResult has been enriched with the new types (as the documentation tells).

WHY

Regarding the Slack discussion about Shutterstock company. In that case we should create a new object type only for stackable operations.

@patryksmolarz patryksmolarz self-assigned this Nov 14, 2024
@marcinrog marcinrog changed the title new redeem stackable object type, new redeem stackable object type Nov 14, 2024
Copy link
Contributor

@p-zielinski p-zielinski left a comment

Choose a reason for hiding this comment

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

napewno jest błąd z amount: number i chyba z status - reszta to takie czepianie się by było idealnie :)

metadata?: Record<string, any>
result: 'SUCCESS' | 'FAILURE'
voucher?: VouchersResponse
customer?: SimpleCustomer
Copy link
Contributor

Choose a reason for hiding this comment

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

j.w.

Copy link
Contributor

@p-zielinski p-zielinski left a comment

Choose a reason for hiding this comment

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

Potestowałem i znalazłem sporo błędów:
Screenshot 2024-11-28 at 10 39 38
Screenshot 2024-11-28 at 10 39 53

By zobaczyć te błędy u siebie podmień:
packages/sdk/src/Redemptions.ts

import * as T from './types/Redemptions'

import { encode, isObject, isString } from './helpers'

import type { RequestController } from './RequestController'

export class Redemptions {
	constructor(private client: RequestController) {}

	/**
	 * @see https://docs.voucherify.io/reference/redeem-voucher
	 */
	public redeem(code: string, body: T.RedemptionsRedeemBody = {}) {
		return this.client.post<T.RedemptionsRedeemResponse>(`/vouchers/${encode(code)}/redemption`, body)
	}
	/**
	 * @see https://docs.voucherify.io/reference/redeem-stacked-discounts
	 */
	public redeemStackable(params: T.RedemptionsRedeemStackableParams) {
		const x: T.RedemptionsRedeemStackableResponse = {
			redemptions: [
				{
					id: 'r_0fbe41b248d2d11481',
					date: '2024-11-28T09:25:43.843Z',
					order: {
						id: 'ord_0fbe41b24252d1147a',
						source_id: null,
						status: 'PAID',
						customer_id: null,
						referrer_id: null,
						applied_discount_amount: 0,
						total_applied_discount_amount: 0,
						metadata: {},
						created_at: '2024-11-28T09:25:43.820Z',
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					voucher: {
						id: 'v_8ZKDUCPNXbVWcoYdc7qtJmNILaq20730',
						code: 'XYZ1',
						discount: {
							type: 'AMOUNT',
							amount_off: 100,
							effect: 'APPLY_TO_ORDER',
						},
						type: 'DISCOUNT_VOUCHER',
						campaign: 'xyz1',
						campaign_id: 'camp_DytAZkSytZiLXgW47l6AAMnh',
						is_referral_code: false,
						category_id: null,
						active: true,
						created_at: '2024-11-28T09:24:42.386Z',
						updated_at: '2024-11-28T09:25:43.836Z',
						redemption: {
							quantity: null,
							redeemed_quantity: 1,
						},
						start_date: null,
						expiration_date: null,
						metadata: {},
						object: 'voucher',
					},
					metadata: {
						sale_channel: 'kiosk',
						store_id: 'AC',
						order_serving_mode: 'Take Away',
						store_aloha_id: '048',
						store_name: 'AC',
					},
					object: 'redemption',
				},
			],
			order: {
				id: 'ord_0fbe41b24252d1147a',
				source_id: null,
				created_at: '2024-11-28T09:25:43.820Z',
				updated_at: null,
				status: 'PAID',
				applied_discount_amount: 0,
				total_applied_discount_amount: 0,
				metadata: {},
				customer_id: null,
				referrer_id: null,
				object: 'order',
				redemptions: {
					r_0fbe41b248d2d11481: {
						date: '2024-11-28T09:25:43.843Z',
						related_object_type: 'voucher',
						related_object_id: 'v_8ZKDUCPNXbVWcoYdc7qtJmNILaq20730',
						related_object_parent_id: 'camp_DytAZkSytZiLXgW47l6AAMnh',
					},
				},
			},
			inapplicable_redeemables: [],
			skipped_redeemables: [],
		}

		const y: T.RedemptionsRedeemStackableResponse = {
			redemptions: [
				{
					id: 'r_0fbe4384b90de6c277',
					date: '2024-11-28T09:33:41.476Z',
					order: {
						id: 'ord_0fbe4384b10de6c265',
						source_id: null,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					voucher: {
						id: 'v_8ZKDUCPNXbVWcoYdc7qtJmNILaq20730',
						code: 'XYZ1',
						discount: {
							type: 'AMOUNT',
							amount_off: 100,
							effect: 'APPLY_TO_ORDER',
						},
						type: 'DISCOUNT_VOUCHER',
						campaign: 'xyz1',
						campaign_id: 'camp_DytAZkSytZiLXgW47l6AAMnh',
						is_referral_code: false,
						category_id: null,
						active: true,
						created_at: '2024-11-28T09:24:42.386Z',
						updated_at: '2024-11-28T09:33:41.471Z',
						redemption: {
							quantity: null,
							redeemed_quantity: 1,
						},
						start_date: null,
						expiration_date: null,
						metadata: {},
						object: 'voucher',
					},
					redemption: 'r_0fbe4384b78de6c276',
					metadata: {
						sale_channel: 'kiosk',
						store_id: 'AC',
						order_serving_mode: 'Take Away',
						store_aloha_id: '048',
						store_name: 'AC',
					},
					object: 'redemption',
				},
				{
					id: 'r_0fbe4384b90de6c278',
					date: '2024-11-28T09:33:41.476Z',
					order: {
						id: 'ord_0fbe4384b10de6c265',
						source_id: null,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					promotion_tier: {
						id: 'promo_5uagb1IBw3NFSu8Jjff1ilv6',
						name: 'xyz3',
						banner: null,
						campaign: {
							id: 'camp_07Hi8xj8x4KUtKbvYNLW1QL6',
						},
						metadata: {},
					},
					redemption: 'r_0fbe4384b78de6c276',
					metadata: {
						sale_channel: 'kiosk',
						store_id: 'AC',
						order_serving_mode: 'Take Away',
						store_aloha_id: '048',
						store_name: 'AC',
					},
					object: 'redemption',
				},
			],
			parent_redemption: {
				id: 'r_0fbe4384b78de6c276',
				date: '2024-11-28T09:33:41.476Z',
				order: {
					id: 'ord_0fbe4384b10de6c265',
					source_id: null,
					status: 'PAID',
					customer_id: null,
					referrer_id: null,
					applied_discount_amount: 0,
					total_applied_discount_amount: 0,
					metadata: {},
					created_at: '2024-11-28T09:33:41.461Z',
					object: 'order',
				},
				result: 'SUCCESS',
				status: 'SUCCEEDED',
				metadata: {
					sale_channel: 'kiosk',
					store_id: 'AC',
					order_serving_mode: 'Take Away',
					store_aloha_id: '048',
					store_name: 'AC',
				},
				object: 'redemption',
			},
			order: {
				id: 'ord_0fbe4384b10de6c265',
				source_id: null,
				created_at: '2024-11-28T09:33:41.461Z',
				updated_at: null,
				status: 'PAID',
				applied_discount_amount: 0,
				total_applied_discount_amount: 0,
				metadata: {},
				customer_id: null,
				referrer_id: null,
				object: 'order',
				redemptions: {
					r_0fbe4384b78de6c276: {
						date: '2024-11-28T09:33:41.476Z',
						related_object_type: 'redemption',
						related_object_id: 'r_0fbe4384b78de6c276',
						stacked: ['r_0fbe4384b90de6c277', 'r_0fbe4384b90de6c278'],
					},
				},
			},
			inapplicable_redeemables: [
				{
					status: 'INAPPLICABLE',
					id: 'xyz2',
					object: 'voucher',
					result: {
						error: {
							code: 400,
							key: 'missing_amount',
							message: 'Missing amount',
							details: 'Amount is required when redeeming a GIFT_VOUCHER',
							request_id: 'v-0fbe4384ad0aaf3e29',
						},
						details: {
							message: 'Missing amount',
							key: 'missing_amount',
						},
					},
					metadata: {},
				},
			],
			skipped_redeemables: [],
		}

		const z: T.RedemptionsRedeemStackableResponse = {
			redemptions: [
				{
					id: 'r_0fbe4416a1d09bca64',
					date: '2024-11-28T09:36:10.887Z',
					order: {
						id: 'ord_0fbe441694d09bca4e',
						source_id: null,
						amount: 0,
						discount_amount: 0,
						applied_discount_amount: 0,
						total_discount_amount: 0,
						total_applied_discount_amount: 0,
						total_amount: 0,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					voucher: {
						id: 'v_8ZKDUCPNXbVWcoYdc7qtJmNILaq20730',
						code: 'XYZ1',
						discount: {
							type: 'AMOUNT',
							amount_off: 100,
							effect: 'APPLY_TO_ORDER',
						},
						type: 'DISCOUNT_VOUCHER',
						campaign: 'xyz1',
						campaign_id: 'camp_DytAZkSytZiLXgW47l6AAMnh',
						is_referral_code: false,
						category_id: null,
						active: true,
						created_at: '2024-11-28T09:24:42.386Z',
						updated_at: '2024-11-28T09:36:10.880Z',
						redemption: {
							quantity: null,
							redeemed_quantity: 3,
						},
						start_date: null,
						expiration_date: null,
						metadata: {},
						object: 'voucher',
					},
					redemption: 'r_0fbe4416a0109bca5d',
					metadata: {
						sale_channel: 'kiosk',
						store_id: 'AC',
						order_serving_mode: 'Take Away',
						store_aloha_id: '048',
						store_name: 'AC',
					},
					object: 'redemption',
				},
				{
					id: 'r_0fbe4416a1d09bca65',
					date: '2024-11-28T09:36:10.887Z',
					amount: 0,
					order: {
						id: 'ord_0fbe441694d09bca4e',
						source_id: null,
						amount: 0,
						discount_amount: 0,
						applied_discount_amount: 0,
						total_discount_amount: 0,
						total_applied_discount_amount: 0,
						total_amount: 0,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					voucher: {
						id: 'v_zR2b98EZ37iWq26mrmo37QeDI6lL7wjU',
						code: 'XYZ2',
						gift: {
							amount: 200,
							balance: 200,
							effect: 'APPLY_TO_ORDER',
						},
						type: 'GIFT_VOUCHER',
						campaign: 'xyz2',
						campaign_id: 'camp_sIGFWgbFbuSq8uYDl4zF9UAF',
						is_referral_code: false,
						category_id: null,
						active: true,
						created_at: '2024-11-28T09:32:09.449Z',
						updated_at: '2024-11-28T09:36:10.880Z',
						redemption: {
							quantity: null,
							redeemed_quantity: 1,
							redeemed_amount: 0,
						},
						start_date: null,
						expiration_date: null,
						metadata: {},
						object: 'voucher',
					},
					redemption: 'r_0fbe4416a0109bca5d',
					metadata: {
						sale_channel: 'kiosk',
						store_id: 'AC',
						order_serving_mode: 'Take Away',
						store_aloha_id: '048',
						store_name: 'AC',
					},
					object: 'redemption',
				},
				{
					id: 'r_0fbe4416a1d09bca66',
					date: '2024-11-28T09:36:10.887Z',
					order: {
						id: 'ord_0fbe441694d09bca4e',
						source_id: null,
						amount: 0,
						discount_amount: 0,
						applied_discount_amount: 0,
						total_discount_amount: 0,
						total_applied_discount_amount: 0,
						total_amount: 0,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					promotion_tier: {
						id: 'promo_5uagb1IBw3NFSu8Jjff1ilv6',
						name: 'xyz3',
						banner: null,
						campaign: {
							id: 'camp_07Hi8xj8x4KUtKbvYNLW1QL6',
						},
						metadata: {},
					},
					redemption: 'r_0fbe4416a0109bca5d',
					metadata: {
						sale_channel: 'kiosk',
						store_id: 'AC',
						order_serving_mode: 'Take Away',
						store_aloha_id: '048',
						store_name: 'AC',
					},
					object: 'redemption',
				},
			],
			parent_redemption: {
				id: 'r_0fbe4416a0109bca5d',
				date: '2024-11-28T09:36:10.887Z',
				order: {
					id: 'ord_0fbe441694d09bca4e',
					source_id: null,
					status: 'PAID',
					customer_id: null,
					referrer_id: null,
					amount: 0,
					discount_amount: 0,
					applied_discount_amount: 0,
					total_discount_amount: 0,
					total_applied_discount_amount: 0,
					total_amount: 0,
					metadata: {},
					created_at: '2024-11-28T09:36:10.848Z',
					object: 'order',
				},
				result: 'SUCCESS',
				status: 'SUCCEEDED',
				metadata: {
					sale_channel: 'kiosk',
					store_id: 'AC',
					order_serving_mode: 'Take Away',
					store_aloha_id: '048',
					store_name: 'AC',
				},
				object: 'redemption',
			},
			order: {
				id: 'ord_0fbe441694d09bca4e',
				source_id: null,
				created_at: '2024-11-28T09:36:10.848Z',
				updated_at: null,
				status: 'PAID',
				amount: 0,
				discount_amount: 0,
				total_discount_amount: 0,
				total_amount: 0,
				applied_discount_amount: 0,
				total_applied_discount_amount: 0,
				metadata: {},
				customer_id: null,
				referrer_id: null,
				object: 'order',
				redemptions: {
					r_0fbe4416a0109bca5d: {
						date: '2024-11-28T09:36:10.887Z',
						related_object_type: 'redemption',
						related_object_id: 'r_0fbe4416a0109bca5d',
						stacked: ['r_0fbe4416a1d09bca64', 'r_0fbe4416a1d09bca65', 'r_0fbe4416a1d09bca66'],
					},
				},
			},
			inapplicable_redeemables: [],
			skipped_redeemables: [],
		}

		return this.client.post<T.RedemptionsRedeemStackableResponse>(`/redemptions`, params)
	}
	/**
	 * @see https://docs.voucherify.io/reference/get-redemption
	 */
	public get(redemptionId: string) {
		return this.client.get<T.Redemption>(`/redemptions/${encode(redemptionId)}`)
	}
	/**
	 * @see https://docs.voucherify.io/reference/list-redemptions
	 */
	public list(params: T.RedemptionsListParams = {}) {
		return this.client.get<T.RedemptionsListResponse>('/redemptions', params)
	}
	/**
	 * @see https://docs.voucherify.io/reference/vouchers-redemptions
	 */
	public getForVoucher(code: string) {
		return this.client.get<T.RedemptionsGetForVoucherResponse>(`/vouchers/${encode(code)}/redemption`)
	}
	/**
	 * @see https://docs.voucherify.io/reference/rollback-redemption
	 */
	public rollback(redemptionId: string, params?: T.RedemptionsRollbackParams) {
		let queryParams: T.RedemptionsRollbackQueryParams = {}
		let payload: T.RedemptionsRollbackPayload = {}

		if (isString(params)) {
			queryParams.reason = params
		} else if (isObject(params)) {
			const { reason, tracking_id: trackingId, customer } = params

			queryParams = {
				reason: reason ? reason : undefined,
				tracking_id: trackingId ? trackingId : undefined,
			}
			payload = { customer }
		}

		return this.client.post<T.RedemptionsRollbackResponse>(
			`/redemptions/${encode(redemptionId)}/rollback`,
			payload,
			queryParams,
		)
	}
	/**
	 * @see https://docs.voucherify.io/reference/rollback-stackable-redemptions
	 * Types of params and queryParams WILL be changed in future - please do not depend on it!
	 */
	public rollbackStackable(parentRedemptionId: string, params?: any, queryParams?: any) {
		const x: T.RedemptionsRollbackStackableResponse = {
			rollbacks: [
				{
					id: 'rr_0fbe42b66fcde6a5b1',
					date: '2024-11-28T09:30:10.281Z',
					order: {
						id: 'ord_0fbe41b24252d1147a',
						source_id: null,
						status: 'CANCELED',
						customer_id: null,
						referrer_id: null,
						metadata: {},
						created_at: '2024-11-28T09:25:43.820Z',
						updated_at: '2024-11-28T09:30:10.286Z',
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					voucher: {
						id: 'v_8ZKDUCPNXbVWcoYdc7qtJmNILaq20730',
						code: 'XYZ1',
						discount: {
							type: 'AMOUNT',
							amount_off: 100,
							effect: 'APPLY_TO_ORDER',
						},
						type: 'DISCOUNT_VOUCHER',
						campaign: 'xyz1',
						campaign_id: 'camp_DytAZkSytZiLXgW47l6AAMnh',
						is_referral_code: false,
						category_id: null,
						active: true,
						created_at: '2024-11-28T09:24:42.386Z',
						updated_at: '2024-11-28T09:30:10.278Z',
						redemption: {
							quantity: null,
							redeemed_quantity: 0,
						},
						start_date: null,
						expiration_date: null,
						metadata: {},
						object: 'voucher',
					},
					redemption: 'r_0fbe41b248d2d11481',
					metadata: null,
					object: 'redemption_rollback',
				},
			],
			order: {
				id: 'ord_0fbe41b24252d1147a',
				source_id: null,
				created_at: '2024-11-28T09:25:43.820Z',
				updated_at: '2024-11-28T09:30:10.286Z',
				status: 'CANCELED',
				metadata: {},
				customer_id: null,
				referrer_id: null,
				object: 'order',
				redemptions: {
					r_0fbe41b248d2d11481: {
						date: '2024-11-28T09:25:43.843Z',
						rollback_id: 'rr_0fbe42b66fcde6a5b1',
						rollback_date: '2024-11-28T09:30:10.281Z',
						related_object_type: 'voucher',
						related_object_id: 'v_8ZKDUCPNXbVWcoYdc7qtJmNILaq20730',
						related_object_parent_id: 'camp_DytAZkSytZiLXgW47l6AAMnh',
					},
				},
			},
		}

		const y: T.RedemptionsRollbackStackableResponse = {
			rollbacks: [
				{
					id: 'rr_0fbe447a7b4de6e3eb',
					date: '2024-11-28T09:37:53.133Z',
					order: {
						id: 'ord_0fbe4384b10de6c265',
						source_id: null,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					voucher: {
						id: 'v_8ZKDUCPNXbVWcoYdc7qtJmNILaq20730',
						code: 'XYZ1',
						discount: {
							type: 'AMOUNT',
							amount_off: 100,
							effect: 'APPLY_TO_ORDER',
						},
						type: 'DISCOUNT_VOUCHER',
						campaign: 'xyz1',
						campaign_id: 'camp_DytAZkSytZiLXgW47l6AAMnh',
						is_referral_code: false,
						category_id: null,
						active: true,
						created_at: '2024-11-28T09:24:42.386Z',
						updated_at: '2024-11-28T09:37:53.125Z',
						redemption: {
							quantity: null,
							redeemed_quantity: 1,
						},
						start_date: null,
						expiration_date: null,
						metadata: {},
						object: 'voucher',
					},
					redemption: 'r_0fbe4384b90de6c277',
					metadata: null,
					object: 'redemption_rollback',
				},
				{
					id: 'rr_0fbe447a7b4de6e3ec',
					date: '2024-11-28T09:37:53.133Z',
					order: {
						id: 'ord_0fbe4384b10de6c265',
						source_id: null,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					promotion_tier: {
						id: 'promo_5uagb1IBw3NFSu8Jjff1ilv6',
						name: 'xyz3',
						banner: null,
						campaign: {
							id: 'camp_07Hi8xj8x4KUtKbvYNLW1QL6',
						},
						metadata: {},
					},
					redemption: 'r_0fbe4384b90de6c278',
					metadata: null,
					object: 'redemption_rollback',
				},
			],
			parent_rollback: {
				id: 'rr_0fbe447a708de6e3e7',
				date: '2024-11-28T09:37:53.090Z',
				order: {
					id: 'ord_0fbe4384b10de6c265',
					source_id: null,
					status: 'CANCELED',
					customer_id: null,
					referrer_id: null,
					metadata: {},
					created_at: '2024-11-28T09:33:41.461Z',
					updated_at: '2024-11-28T09:37:53.143Z',
					object: 'order',
				},
				result: 'SUCCESS',
				status: 'SUCCEEDED',
				redemption: 'r_0fbe4384b78de6c276',
				metadata: null,
				object: 'redemption_rollback',
			},
			order: {
				id: 'ord_0fbe4384b10de6c265',
				source_id: null,
				created_at: '2024-11-28T09:33:41.461Z',
				updated_at: '2024-11-28T09:37:53.155Z',
				status: 'CANCELED',
				metadata: {},
				customer_id: null,
				referrer_id: null,
				object: 'order',
				redemptions: {
					r_0fbe4384b78de6c276: {
						date: '2024-11-28T09:33:41.476Z',
						rollback_id: 'rr_0fbe447a708de6e3e7',
						rollback_date: '2024-11-28T09:37:53.090Z',
						related_object_type: 'redemption',
						related_object_id: 'r_0fbe4384b78de6c276',
						stacked: ['r_0fbe4384b90de6c277', 'r_0fbe4384b90de6c278'],
						rollback_stacked: ['rr_0fbe447a7b4de6e3eb', 'rr_0fbe447a7b4de6e3ec'],
					},
				},
			},
		}

		const z: T.RedemptionsRollbackStackableResponse = {
			rollbacks: [
				{
					id: 'rr_0fbe444ee9909bd149',
					date: '2024-11-28T09:37:08.518Z',
					order: {
						id: 'ord_0fbe441694d09bca4e',
						source_id: null,
						amount: 0,
						total_amount: 0,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					voucher: {
						id: 'v_8ZKDUCPNXbVWcoYdc7qtJmNILaq20730',
						code: 'XYZ1',
						discount: {
							type: 'AMOUNT',
							amount_off: 100,
							effect: 'APPLY_TO_ORDER',
						},
						type: 'DISCOUNT_VOUCHER',
						campaign: 'xyz1',
						campaign_id: 'camp_DytAZkSytZiLXgW47l6AAMnh',
						is_referral_code: false,
						category_id: null,
						active: true,
						created_at: '2024-11-28T09:24:42.386Z',
						updated_at: '2024-11-28T09:37:08.512Z',
						redemption: {
							quantity: null,
							redeemed_quantity: 2,
						},
						start_date: null,
						expiration_date: null,
						metadata: {},
						object: 'voucher',
					},
					redemption: 'r_0fbe4416a1d09bca64',
					metadata: null,
					object: 'redemption_rollback',
				},
				{
					id: 'rr_0fbe444ee9909bd14a',
					date: '2024-11-28T09:37:08.518Z',
					amount: 0,
					order: {
						id: 'ord_0fbe441694d09bca4e',
						source_id: null,
						amount: 0,
						discount_amount: 0,
						total_discount_amount: 0,
						total_amount: 0,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					voucher: {
						id: 'v_zR2b98EZ37iWq26mrmo37QeDI6lL7wjU',
						code: 'XYZ2',
						gift: {
							amount: 200,
							balance: 200,
							effect: 'APPLY_TO_ORDER',
						},
						type: 'GIFT_VOUCHER',
						campaign: 'xyz2',
						campaign_id: 'camp_sIGFWgbFbuSq8uYDl4zF9UAF',
						is_referral_code: false,
						category_id: null,
						active: true,
						created_at: '2024-11-28T09:32:09.449Z',
						updated_at: '2024-11-28T09:37:08.512Z',
						redemption: {
							quantity: null,
							redeemed_quantity: 0,
							redeemed_amount: 0,
						},
						start_date: null,
						expiration_date: null,
						metadata: {},
						object: 'voucher',
					},
					redemption: 'r_0fbe4416a1d09bca65',
					metadata: null,
					object: 'redemption_rollback',
				},
				{
					id: 'rr_0fbe444ee9909bd14b',
					date: '2024-11-28T09:37:08.518Z',
					order: {
						id: 'ord_0fbe441694d09bca4e',
						source_id: null,
						amount: 0,
						discount_amount: 0,
						total_discount_amount: 0,
						total_amount: 0,
						metadata: {},
						object: 'order',
					},
					result: 'SUCCESS',
					status: 'SUCCEEDED',
					promotion_tier: {
						id: 'promo_5uagb1IBw3NFSu8Jjff1ilv6',
						name: 'xyz3',
						banner: null,
						campaign: {
							id: 'camp_07Hi8xj8x4KUtKbvYNLW1QL6',
						},
						metadata: {},
					},
					redemption: 'r_0fbe4416a1d09bca66',
					metadata: null,
					object: 'redemption_rollback',
				},
			],
			parent_rollback: {
				id: 'rr_0fbe444ee6109bd143',
				date: '2024-11-28T09:37:08.504Z',
				order: {
					id: 'ord_0fbe441694d09bca4e',
					source_id: null,
					status: 'CANCELED',
					customer_id: null,
					referrer_id: null,
					amount: 0,
					total_amount: 0,
					metadata: {},
					created_at: '2024-11-28T09:36:10.848Z',
					updated_at: '2024-11-28T09:37:08.522Z',
					object: 'order',
				},
				result: 'SUCCESS',
				status: 'SUCCEEDED',
				redemption: 'r_0fbe4416a0109bca5d',
				metadata: null,
				object: 'redemption_rollback',
			},
			order: {
				id: 'ord_0fbe441694d09bca4e',
				source_id: null,
				created_at: '2024-11-28T09:36:10.848Z',
				updated_at: '2024-11-28T09:37:08.529Z',
				status: 'CANCELED',
				amount: 0,
				total_amount: 0,
				metadata: {},
				customer_id: null,
				referrer_id: null,
				object: 'order',
				redemptions: {
					r_0fbe4416a0109bca5d: {
						date: '2024-11-28T09:36:10.887Z',
						rollback_id: 'rr_0fbe444ee6109bd143',
						rollback_date: '2024-11-28T09:37:08.504Z',
						related_object_type: 'redemption',
						related_object_id: 'r_0fbe4416a0109bca5d',
						stacked: ['r_0fbe4416a1d09bca64', 'r_0fbe4416a1d09bca65', 'r_0fbe4416a1d09bca66'],
						rollback_stacked: ['rr_0fbe444ee9909bd149', 'rr_0fbe444ee9909bd14a', 'rr_0fbe444ee9909bd14b'],
					},
				},
			},
		}

		return this.client.post<T.RedemptionsRollbackStackableResponse>(
			`/redemptions/${encode(parentRedemptionId)}/rollbacks`,
			params,
			queryParams,
		)
	}
}

@p-zielinski
Copy link
Contributor

Testowałem na 6 requestach.
Polecałbym by Rollback i Redeem nie dzieliły ze sobą tego samego typu - moim zdaniem jest tam zbyt wiele niuansów i różnic by to dobrze utrzymywać.

@p-zielinski
Copy link
Contributor

Nawiązując do naszej rozmowy brakuje w paru miejscach | null (ale to możemy olać jak zdecyduje tak Marcin) a także do poprawy jest RedemptionsRedeemStackableOrderResponse.redeemptions<>related_object_type - ktory jest błędny.

redemptions?: Record<
string,
{
date: string
rollback_id?: string
rollback_date?: string
related_object_type: 'redemption'
related_object_type: 'redemption' | 'voucher' | 'promotion_tier'
Copy link
Contributor

Choose a reason for hiding this comment

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

a promotion_stack nie?

Copy link
Author

Choose a reason for hiding this comment

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

dokumentacja nic nie mówi o takim unionie niestety, więc nie wiem

Copy link
Contributor

Choose a reason for hiding this comment

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

Chodziło o to byś sprawdził, robiąc redeema z promotion stackiem:
Ja teraz zrobiłem i jest:
Screenshot 2024-11-28 at 14 14 01
więc proszę dodaj promotion_stack jako możliwość

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants