-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 changed file
with
109 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,138 +8,135 @@ const returnUrl = process.env.TEST_RETURN_URL || ""; | |
const notifyUrl = process.env.TEST_NOTIFY_URL || ""; | ||
const clientBackUrl = process.env.TEST_CLIENT_BACK_URL || ""; | ||
|
||
test("buildCheckCode", async () => { | ||
const client = new NewebpayClient({ | ||
merchantId, | ||
hashKey, | ||
hashIV, | ||
env: "sandbox", | ||
}); | ||
const data = client.buildCheckCode({ | ||
MerchantID: "TWD987086921", | ||
Amt: 10, | ||
MerchantOrderNo: "MyCompanyOrder_1638423361", | ||
TradeNo: "21120214151152468", | ||
describe("MPG API", () => { | ||
let client: NewebpayClient; | ||
|
||
beforeEach(() => { | ||
client = new NewebpayClient({ | ||
merchantId, | ||
hashKey, | ||
hashIV, | ||
env: "sandbox", | ||
}); | ||
}); | ||
|
||
expect(data).toBe( | ||
"7C5091FB35A16FD222C197C4B711FE2A8848D9BFD01A098A62EC9C4C45C78CAF" | ||
); | ||
}); | ||
test("should getPaymentFormHTML for credit card agreement", async () => { | ||
const data = client.getPaymentFormHTML({ | ||
NotifyURL: "https://webhook.site/dcf03f1f-e2de-42d8-b39f-c5387a325508", | ||
ReturnURL: "https://webhook.site/dcf03f1f-e2de-42d8-b39f-c5387a325508", | ||
MerchantOrderNo: Date.now().toString(), | ||
Amt: 10, | ||
ItemDesc: "約定信用卡", | ||
OrderComment: "約定信用卡", | ||
Email: "[email protected]", | ||
TokenTerm: "UserID", | ||
CREDITAGREEMENT: 1, | ||
}); | ||
|
||
test("getPaymentFormHTML for credit card agreement", async () => { | ||
const client = new NewebpayClient({ | ||
merchantId, | ||
hashKey, | ||
hashIV, | ||
env: "sandbox", | ||
}); | ||
const data = client.getPaymentFormHTML({ | ||
NotifyURL: "https://webhook.site/dcf03f1f-e2de-42d8-b39f-c5387a325508", | ||
ReturnURL: "https://webhook.site/dcf03f1f-e2de-42d8-b39f-c5387a325508", | ||
MerchantOrderNo: Date.now().toString(), | ||
Amt: 10, | ||
ItemDesc: "約定信用卡", | ||
OrderComment: "約定信用卡", | ||
Email: "[email protected]", | ||
TokenTerm: "UserID", | ||
CREDITAGREEMENT: 1, | ||
console.log(data); | ||
expect(data).toBeDefined(); | ||
}); | ||
|
||
console.log(data); | ||
}); | ||
test("should buildCheckCode success", async () => { | ||
const data = client.buildCheckCode({ | ||
MerchantID: "TWD987086921", | ||
Amt: 10, | ||
MerchantOrderNo: "MyCompanyOrder_1638423361", | ||
TradeNo: "21120214151152468", | ||
}); | ||
|
||
test("createPeriodicPaymentHTML", async () => { | ||
const client = new NewebpayClient({ | ||
merchantId, | ||
hashKey, | ||
hashIV, | ||
env: "sandbox", | ||
expect(data).toBe( | ||
"7C5091FB35A16FD222C197C4B711FE2A8848D9BFD01A098A62EC9C4C45C78CAF" | ||
); | ||
}); | ||
const data = client.createPeriodicPaymentHTML({ | ||
LangType: "zh-Tw", | ||
MerOrderNo: "2025010812000000", | ||
ProdDesc: "約定信用卡", | ||
PeriodAmt: 10, | ||
PeriodType: "M", | ||
PeriodPoint: "01", | ||
PeriodStartType: 1, | ||
PeriodTimes: 99, | ||
PeriodFirstdate: "2025/01/08", | ||
PeriodMemo: "約定信用卡", | ||
PayerEmail: "[email protected]", | ||
EmailModify: 0, | ||
PaymentInfo: "N", | ||
OrderInfo: "N", | ||
ReturnURL: returnUrl, | ||
NotifyURL: notifyUrl, | ||
BackURL: clientBackUrl, | ||
UNIONPAY: 0, | ||
}); | ||
|
||
describe("periodic payment API", () => { | ||
let client: NewebpayClient; | ||
|
||
beforeEach(() => { | ||
client = new NewebpayClient({ | ||
merchantId, | ||
hashKey, | ||
hashIV, | ||
env: "sandbox", | ||
}); | ||
}); | ||
|
||
console.log(data); | ||
}); | ||
test("should createPeriodicPaymentHTML with html", async () => { | ||
const client = new NewebpayClient({ | ||
merchantId, | ||
hashKey, | ||
hashIV, | ||
env: "sandbox", | ||
}); | ||
const data = client.createPeriodicPaymentHTML({ | ||
LangType: "zh-Tw", | ||
MerOrderNo: "2025010812000000", | ||
ProdDesc: "約定信用卡", | ||
PeriodAmt: 10, | ||
PeriodType: "M", | ||
PeriodPoint: "01", | ||
PeriodStartType: 1, | ||
PeriodTimes: 99, | ||
PeriodFirstdate: "2025/01/08", | ||
PeriodMemo: "約定信用卡", | ||
PayerEmail: "[email protected]", | ||
EmailModify: 0, | ||
PaymentInfo: "N", | ||
OrderInfo: "N", | ||
ReturnURL: returnUrl, | ||
NotifyURL: notifyUrl, | ||
BackURL: clientBackUrl, | ||
UNIONPAY: 0, | ||
}); | ||
|
||
test("parseCreatePeriodicPaymentResponse", async () => { | ||
const client = new NewebpayClient({ | ||
merchantId, | ||
hashKey, | ||
hashIV, | ||
env: "sandbox", | ||
console.log(data); | ||
expect(data).toBeDefined(); | ||
}); | ||
|
||
// TODO: create this file when you get the response from the API | ||
const rawResponse = fs.readFileSync( | ||
"./test/periodicPaymentCreationResponse.txt", | ||
"utf8" | ||
); | ||
const response = client.parseCreatePeriodicPaymentResponse(rawResponse); | ||
|
||
console.log(response); | ||
expect(response.Status).toBeDefined(); | ||
expect(response.Message).toBeDefined(); | ||
expect(response.Result).toBeDefined(); | ||
expect(response.Result.DateArray).toBeDefined(); | ||
}); | ||
test("should parseCreatePeriodicPaymentResponse", async () => { | ||
// TODO: create this file when you get the response from the API | ||
const rawResponse = fs.readFileSync( | ||
"./test/periodicPaymentCreationResponse.txt", | ||
"utf8" | ||
); | ||
const response = client.parseCreatePeriodicPaymentResponse(rawResponse); | ||
|
||
test("periodicPaymentCreationFailResponse", async () => { | ||
const client = new NewebpayClient({ | ||
merchantId, | ||
hashKey, | ||
hashIV, | ||
env: "sandbox", | ||
console.log(response); | ||
expect(response.Status).toBeDefined(); | ||
expect(response.Message).toBeDefined(); | ||
expect(response.Result).toBeDefined(); | ||
expect(response.Result.DateArray).toBeDefined(); | ||
}); | ||
const rawResponse = fs.readFileSync( | ||
"./test/periodicPaymentCreationFailResponse.txt", | ||
"utf8" | ||
); | ||
const response = client.parseCreatePeriodicPaymentResponse(rawResponse); | ||
|
||
console.log(response); | ||
}); | ||
test("should periodicPaymentCreationFailResponse", async () => { | ||
const rawResponse = fs.readFileSync( | ||
"./test/periodicPaymentCreationFailResponse.txt", | ||
"utf8" | ||
); | ||
const response = client.parseCreatePeriodicPaymentResponse(rawResponse); | ||
|
||
test("parsePeriodicPaymentResponse", async () => { | ||
const client = new NewebpayClient({ | ||
merchantId, | ||
hashKey, | ||
hashIV, | ||
env: "sandbox", | ||
console.log(response); | ||
}); | ||
|
||
// TODO: create this file when you get the response from the API | ||
const rawResponse = fs.readFileSync( | ||
"./test/periodicPaymentResponse.txt", | ||
"utf8" | ||
); | ||
const response = client.parsePeriodicPaymentResponse(rawResponse); | ||
|
||
expect(response.Status).toBeDefined(); | ||
expect(response.Message).toBeDefined(); | ||
expect(response.Result).toBeDefined(); | ||
expect(response.Result.AuthBank).toBeDefined(); | ||
test("should parsePeriodicPaymentResponse", async () => { | ||
// TODO: create this file when you get the response from the API | ||
const rawResponse = fs.readFileSync( | ||
"./test/periodicPaymentResponse.txt", | ||
"utf8" | ||
); | ||
|
||
const response = client.parsePeriodicPaymentResponse(rawResponse); | ||
|
||
expect(response.Status).toBeDefined(); | ||
expect(response.Message).toBeDefined(); | ||
expect(response.Result).toBeDefined(); | ||
expect(response.Result.AuthBank).toBeDefined(); | ||
}); | ||
}); | ||
|
||
describe("period alter API", () => { | ||
describe("periodic payment alter API", () => { | ||
let client: NewebpayClient; | ||
|
||
beforeEach(() => { | ||
|