Skip to content

Commit

Permalink
add message to gift card
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiAbdou committed Sep 26, 2024
1 parent 3a86dad commit 33e8a6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/modules/member/events/member-activated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export async function onMemberActivated({
.executeTakeFirstOrThrow();

const giftCardResult = await createGiftCard({
customer: {
expiresOn: dayjs().add(1, 'week').format('YYYY-MM-DD'),
initialValue: '50.00',
note: 'This is for member activation.',
recipient: {
email: member.email,
firstName: member.firstName,
lastName: member.lastName,
},
expiresOn: dayjs().add(1, 'week').format('YYYY-MM-DD'),
initialValue: '50.00',
note: 'This is for member activation.',
});

if (!giftCardResult.ok) {
Expand Down
10 changes: 6 additions & 4 deletions packages/core/src/modules/shopify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ async function getCustomerByEmail(
* @see https://shopify.dev/docs/api/admin-rest/2024-07/resources/gift-card#resource-object
*/
type GiftCard = {
customer: Customer;
expiresOn: string;
initialValue: string;
message?: string;
note?: string;
recipient: Customer;
};

type CreateGiftCardResult = Result<{}>;
Expand All @@ -174,18 +175,19 @@ type CreateGiftCardResult = Result<{}>;
export async function createGiftCard(
card: GiftCard
): Promise<CreateGiftCardResult> {
const customerResult = await getOrCreateCustomer(card.customer);
const customerResult = await getOrCreateCustomer(card.recipient);

if (!customerResult.ok) {
return fail(customerResult);
}

const body = JSON.stringify({
gift_card: {
customer_id: customerResult.data.id,
expires_on: card.expiresOn,
initial_value: card.initialValue,
message: card.message,
note: card.note,
recipient_id: customerResult.data.id,
},
});

Expand All @@ -200,7 +202,7 @@ export async function createGiftCard(
const data = await response.json();

if (!response.ok) {
const error = new Error('Failed to create Goody order.');
const error = new Error('Failed to create Shopify gift card.');

reportException(error, {
data,
Expand Down

0 comments on commit 33e8a6d

Please sign in to comment.