This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d5fb00
commit 63da4ea
Showing
9 changed files
with
148 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/backend-serverless/src/services/transaction-validation/check-refund-balance.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { PaymentRecord, RefundRecord } from '@prisma/client'; | ||
import { TOKEN_PROGRAM_ID, decodeTransferCheckedInstruction } from '@solana/spl-token'; | ||
import { delay } from '../../utilities/delay.utility.js'; | ||
import { fetchTransaction } from '../fetch-transaction.service.js'; | ||
import { fetchBalance } from '../helius.service.js'; | ||
|
||
export async function checkRefundBalance( | ||
associatedPaymentRecord: PaymentRecord, | ||
refundRecord: RefundRecord, | ||
account: string, | ||
amount: number | ||
) { | ||
if (associatedPaymentRecord.transactionSignature == null) { | ||
throw new Error('Payment transaction not found.'); | ||
} | ||
|
||
let transaction; | ||
|
||
while (transaction == null) { | ||
await delay(1000); | ||
|
||
transaction = await fetchTransaction(associatedPaymentRecord.transactionSignature); | ||
} | ||
|
||
const transferInstruction = transaction.instructions[transaction.instructions.length - 2]; | ||
|
||
if (transferInstruction.programId.toBase58() != TOKEN_PROGRAM_ID.toBase58()) { | ||
const error = new Error('Invalid transaction.' + transferInstruction.programId.toBase58()); | ||
throw error; | ||
} | ||
|
||
const decodedInstruction = decodeTransferCheckedInstruction(transferInstruction); | ||
|
||
const mint = decodedInstruction.keys.mint; | ||
|
||
const balance = await fetchBalance(account, mint.pubkey.toBase58()); | ||
|
||
return balance >= refundRecord.usdcAmount; | ||
} |
Oops, something went wrong.
63da4ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shopifydocs-solana-pay – ./apps/docs
shopifydocs-solana-pay.vercel.app
shopifydocs-solana-pay-solana-labs.vercel.app
shopifydocs.solanapay.com
shopifydocs-solana-pay-git-main-solana-labs.vercel.app
commercedocs.solanapay.com
63da4ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shopify-payment-ui – ./apps/payment-ui
shopify-payment-ui-git-production-solana-labs.vercel.app
shopify-payment-ui.vercel.app
shopify-payment-ui-solana-labs.vercel.app
pay.solanapay.com
63da4ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shopify-merchant-ui – ./apps/merchant-ui
shopify-merchant-ui-solana-labs.vercel.app
shopify-merchant-ui-git-production-solana-labs.vercel.app
shopify-merchant-ui.vercel.app
merchant.solanapay.com