-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Showing
8 changed files
with
142 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { BOTBarcode } from '@/lib/BOTBarcode' | ||
|
||
interface Config { | ||
/** Biller ID (Tax ID + Suffix) */ | ||
billerId: string | ||
|
||
/** Reference No. 1 / Customer No. */ | ||
ref1: string | ||
|
||
/** Reference No. 2 */ | ||
ref2?: string | null | ||
|
||
/** Transaction amount */ | ||
amount?: number | null | ||
} | ||
|
||
/** | ||
* Generate BOT Barcode | ||
* | ||
* @returns Barcode Payload | ||
*/ | ||
export function botBarcode({ billerId, ref1, ref2, amount }: Config) { | ||
return new BOTBarcode(billerId, ref1, ref2, amount) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { billPayment } from '@/generate/promptpay/BillPayment' | ||
|
||
export class BOTBarcode { | ||
public billerId: string | ||
public ref1: string | ||
public ref2: string | null | ||
public amount: number | null | ||
|
||
constructor( | ||
billerId: string, | ||
ref1: string, | ||
ref2: string | null = null, | ||
amount: number | null = null, | ||
) { | ||
this.billerId = billerId | ||
this.ref1 = ref1 | ||
this.ref2 = ref2 | ||
this.amount = amount | ||
} | ||
|
||
static fromString(payload: string) { | ||
if (!payload.startsWith('|')) { | ||
return null | ||
} | ||
|
||
const data = payload.slice(1).split('\r', 4) | ||
if (data.length != 4) { | ||
return null | ||
} | ||
|
||
const [billerId, ref1, ref2, amount] = data | ||
|
||
return new BOTBarcode( | ||
billerId, | ||
ref1, | ||
ref2.length > 0 ? ref2 : null, | ||
amount != '0' ? Number((parseInt(amount) / 100).toFixed(2)) : null, | ||
) | ||
} | ||
|
||
toString() { | ||
const { billerId, ref1, ref2, amount } = this | ||
const amountStr = amount ? String(Number(amount.toFixed(2)) * 100) : '0' | ||
return `|${billerId}\r${ref1}\r${ref2 ?? ''}\r${amountStr}` | ||
} | ||
|
||
/** | ||
* Converts BOT Barcode to PromptPay QR Tag 30 (Bill Payment) | ||
* | ||
* This method works for some biller, depends on destination bank | ||
* | ||
* @returns QR Code payload | ||
*/ | ||
toQrTag30() { | ||
const { billerId, ref1, ref2, amount } = this | ||
return billPayment({ | ||
billerId, | ||
ref1, | ||
ref2: ref2 ?? undefined, | ||
amount: amount ?? undefined, | ||
}) | ||
} | ||
} |
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