@@ -78,7 +78,7 @@ describe('ATMPayment: Check Params Constraints', () => {
7878 } ) ;
7979} ) ;
8080
81- describe ( 'ATMPayment: html ' , ( ) => {
81+ describe ( 'ATMPayment: Redirect Post Form ' , ( ) => {
8282 const merchant = new Merchant ( 'Test' , TEST_MERCHANT_CONFIG ) ;
8383
8484 const baseParams : BasePaymentParams = {
@@ -91,62 +91,73 @@ describe('ATMPayment: html', () => {
9191
9292 test ( 'Checkout with ' , async ( ) => {
9393 const payment = merchant . createPayment ( ATMPayment , baseParams , {
94- ClientRedirectURL :
95- 'https://payment-stage.ecpay.com.tw/PaymentRule/ATMPaymentInfo' ,
96- ChooseSubPayment : 'BOT' ,
9794 ExpireDate : 7 ,
9895 } ) ;
96+
9997 const html = await payment . checkout ( ) ;
100- // const html = await payment.checkout({
101- // RelateNumber: 'rl-no-1',
102- // TaxType: '1',
103- // Donation: '0',
104- // Print: '0',
105- // InvoiceItemName: 'item1|item2',
106- // InvoiceItemCount: '2|5',
107- // InvoiceItemWord: '台|張',
108- // InvoiceItemPrice: '100|50',
109- // InvoiceRemark: '測試發票備註',
110- // CustomerPhone: '0911111111',
111- // });
112- // console.log(html);
98+ expect ( html . startsWith ( '<form id="_form_aio_checkout"' ) ) . toBe ( true ) ;
11399 } ) ;
114100} ) ;
115101
116- // describe('ATMPayment: placeOrder', () => {
117- // const merchant = new Merchant('Test', {
118- // MerchantID: '2000132',
119- // HashKey: '5294y06JbISpM5x9',
120- // HashIV: 'v77hoKGq4kWxNNIS',
121- // ReturnURL: 'https://api.test.com/our/hook',
122- // });
123-
124- // const baseParams: BasePaymentParams = {
125- // MerchantTradeNo: `nea${getCurrentTaipeiTimeString({ format: 'Serial' })}`,
126- // MerchantTradeDate: getCurrentTaipeiTimeString(),
127- // TotalAmount: 500,
128- // TradeDesc: 'node-ecpay-aio testing order for ATMPayment',
129- // ItemName: 'test item name',
130- // };
131-
132- // test('Placed Order with ', async () => {
133- // const payment = merchant.createPayment(ATMPayment, baseParams, {
134- // ExpireDate: 3,
135- // });
136-
137- // const rsp = await payment.placeOrder({
138- // RelateNumber: 'rl-no-1',
139- // TaxType: '1',
140- // Donation: '0',
141- // Print: '0',
142- // InvoiceItemName: 'item1|item2',
143- // InvoiceItemCount: '2|5',
144- // InvoiceItemWord: '台|張',
145- // InvoiceItemPrice: '100|50',
146- // InvoiceRemark: '測試發票備註',
147- // CustomerPhone: '0911111111',
148- // });
149-
150- // console.log(rsp);
151- // });
152- // });
102+ describe ( 'ATMayment: Place Order' , ( ) => {
103+ jest . setTimeout ( 60000 ) ;
104+ const merchant = new Merchant ( 'Test' , MERCHANT_CONFIG_ASYNC ) ;
105+
106+ const baseParams : BasePaymentParams = {
107+ MerchantTradeDate : getCurrentTaipeiTimeString ( ) ,
108+ TotalAmount : 300 ,
109+ TradeDesc : 'node-ecpay-aio testing order for CVSPayment' ,
110+ ItemName : 'test item name' ,
111+ } ;
112+
113+ const invoice = {
114+ RelateNumber : 'nea-ci' ,
115+ TaxType : '1' ,
116+ Donation : '0' ,
117+ Print : '0' ,
118+ InvoiceItemName : 'item1|item2' ,
119+ InvoiceItemCount : '2|5' ,
120+ InvoiceItemWord : '台|張' ,
121+ InvoiceItemPrice : '100|50' ,
122+ InvoiceRemark : '測試發票備註' ,
123+ CustomerPhone : '0911111111' ,
124+ } ;
125+
126+ test ( 'Must pass when placing a new order' , async ( ) => {
127+ const mTradeNo = `nea${ getCurrentTaipeiTimeString ( { format : 'Serial' } ) } ` ;
128+ const payment = merchant . createPayment ( ATMPayment , {
129+ MerchantTradeNo : mTradeNo ,
130+ ...baseParams ,
131+ } ) ;
132+
133+ const rsp = await payment . placeOrder ( invoice ) ;
134+ expect ( rsp . RtnCode ) . toBe ( 2 ) ;
135+ expect ( rsp . MerchantTradeNo ) . toBe ( mTradeNo ) ;
136+ } ) ;
137+
138+ test ( 'Must be rejected when placing Order with a duplicated MerchantTradeNo' , async ( ) => {
139+ await new Promise ( ( r ) => setTimeout ( r , 500 ) ) ;
140+
141+ const mTradeNo = `nea${ getCurrentTaipeiTimeString ( { format : 'Serial' } ) } ` ;
142+ const payment = merchant . createPayment (
143+ ATMPayment ,
144+ {
145+ MerchantTradeNo : mTradeNo ,
146+ ...baseParams ,
147+ } ,
148+ {
149+ ExpireDate : 3 ,
150+ }
151+ ) ;
152+
153+ try {
154+ const rsp = await payment . placeOrder ( invoice ) ;
155+ const duplicatedRsp = await payment . placeOrder ( invoice ) ;
156+ } catch ( e ) {
157+ expect ( e . name ) . toBe ( 'PlaceOrderError' ) ;
158+ expect ( e . message ) . toBe (
159+ 'Duplicated MerchantTradeNo, create order failed.'
160+ ) ;
161+ }
162+ } ) ;
163+ } ) ;
0 commit comments