This guide describes how to test the paytrail-js-sdk locally, focusing on the recent changes to createAddCardFormRequest.
- Node.js (>= 20)
- npm
To run the unit tests, use the following command:
npm testTo run only the tests related to createAddCardFormRequest:
npm test -- tests/create-add-card-form.test.ts- Ensure you have valid Paytrail Merchant credentials (Merchant ID and Secret Key).
- The current test suite uses default test credentials (
merchantId: 695861,secret: MONISAIPPUAKAUPPIAS).
- Instantiate
PaytrailClientwith your credentials. - Create an
AddCardFormRequestobject with only the business fields:checkoutRedirectSuccessUrlcheckoutRedirectCancelUrllanguage(optional)checkoutCallbackSuccessUrl(optional)checkoutCallbackCancelUrl(optional)
- Call
client.createAddCardFormRequest(request). - Inspect the result. It should contain a
redirectUrl.
import { PaytrailClient, AddCardFormRequest } from '@paytrail/paytrail-js-sdk'
const client = new PaytrailClient({
merchantId: 695861,
secretKey: 'MONISAIPPUAKAUPPIAS',
platformName: 'test'
})
const run = async () => {
const request = new AddCardFormRequest()
request.checkoutRedirectSuccessUrl = 'https://example.com/success'
request.checkoutRedirectCancelUrl = 'https://example.com/cancel'
request.language = 'EN'
try {
const response = await client.createAddCardFormRequest(request)
console.log('Redirect URL:', response.data.redirectUrl)
} catch (error) {
console.error('Error:', error)
}
}
run()