Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Release 1.1.0

## What's Changed

**Breaking Change**: Refactored `createAddCardFormRequest` to internalize signature calculation and authentication parameters. This aligns the method with the rest of the SDK patterns and simplifies usage for developers. The `AddCardFormRequest` model no longer requires `checkoutAccount`, `checkoutMethod`, `checkoutNonce`, `checkoutTimestamp`, `checkoutAlgorithm`, or `signature` to be populated manually.

### Features
- Internalized signature calculation for `createAddCardFormRequest` (matches `createPayment` pattern).
- Implemented Form Post style authentication (Body Auth) for add-card requests.

### Refactoring
- Removed manual authentication fields from `AddCardFormRequest` model.
- Automatically injects merchant credentials and generates HMAC signature within the SDK.

### Testing
- Added unit tests to verify signature generation and payload structure for card form requests.
67 changes: 67 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Testing Guide

This guide describes how to test the `paytrail-js-sdk` locally, focusing on the recent changes to `createAddCardFormRequest`.

## Prerequisites

- Node.js (>= 20)
- npm

## Running Automated Tests

To run the unit tests, use the following command:

```bash
npm test
```

To run only the tests related to `createAddCardFormRequest`:

```bash
npm test -- tests/create-add-card-form.test.ts
```

## Manual / Integration Verification

### Setup
1. Ensure you have valid Paytrail Merchant credentials (Merchant ID and Secret Key).
2. The current test suite uses default test credentials (`merchantId: 695861`, `secret: MONISAIPPUAKAUPPIAS`).

### Test Flow
1. Instantiate `PaytrailClient` with your credentials.
2. Create an `AddCardFormRequest` object with only the business fields:
- `checkoutRedirectSuccessUrl`
- `checkoutRedirectCancelUrl`
- `language` (optional)
- `checkoutCallbackSuccessUrl` (optional)
- `checkoutCallbackCancelUrl` (optional)
3. Call `client.createAddCardFormRequest(request)`.
4. Inspect the result. It should contain a `redirectUrl`.

### Example Code

```typescript
import { PaytrailClient, AddCardFormRequest } from '@paytrail/paytrail-js-sdk';

const client = new PaytrailClient({
merchantId: 1072377,
secretKey: '226382458d7a1a75486c9732881472dd61fff6debfb193afab1f7e8b85131081418380be827a69fc',
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();
```
44 changes: 1 addition & 43 deletions src/models/request/add-card-form.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator'
import { IsNotEmpty, IsOptional, IsString } from 'class-validator'

/**
* Class AddCardFormRequest
Expand All @@ -7,41 +7,6 @@ import { IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator'
*
*/
export class AddCardFormRequest {
/**
* Paytrail account ID.
*/
@IsNotEmpty()
@IsNumber()
checkoutAccount: number

/**
* Used signature algorithm. The same as used by merchant when creating the payment.
*/
@IsNotEmpty()
@IsString()
checkoutAlgorithm: string

/**
* HTTP verb of the request. Always POST for addcard-form.
*/
@IsNotEmpty()
@IsString()
checkoutMethod: string

/**
* Unique identifier for this request.
*/
@IsNotEmpty()
@IsString()
checkoutNonce: string

/**
* ISO 8601 date time.
*/
@IsNotEmpty()
@IsString()
checkoutTimestamp: string

/**
* Merchant's url for user redirect on successful card addition.
*/
Expand All @@ -56,13 +21,6 @@ export class AddCardFormRequest {
@IsString()
checkoutRedirectCancelUrl: string

/**
* Signature calculated from 'checkout-' prefixed POST parameters the same way as calculating signature from headers.
*/
@IsNotEmpty()
@IsString()
signature: string

/**
* Merchant's url called on successful card addition.
*/
Expand Down
3 changes: 0 additions & 3 deletions src/models/request/request-model/item.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { IsNotEmpty, IsNumber, IsOptional, IsString, Length, Max, Min } from 'class-validator'
import 'reflect-metadata'



/**
* Class Item
*
Expand Down Expand Up @@ -104,5 +102,4 @@ export class Item {
@IsOptional()
@Length(0, 50)
public merchant?: string

}
Loading
Loading