Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackfaded committed Aug 12, 2024
1 parent ea27f0a commit 487c39f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
66 changes: 59 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Welcome to the Node SDK for the PAYONE Commerce Platform! This repository contai
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [Error Handling](#error-handling)
- [Client Side](#client-side)
- [Apple Pay](#apple-pay)
- [Contributing](#contributing)
- [Build the library](#build-the-library)
- [Run tests](#run-tests)
Expand All @@ -33,16 +35,66 @@ Welcome to the Node SDK for the PAYONE Commerce Platform! This repository contai

## Installation

```sh
# npm
npm i pcp-server-nodejs-sdk
# yarn
yarn add pcp-server-nodejs-sdk
```

## Usage

### Configuration
To use this SDK you need to construct a `CommunicatorConfiguration` which encapsulate everything needed to connect to the PAYONE Commerce Platform.

```ts
const apiKey = process.env.API_KEY;
const apiSecret = process.env.API_SECRET;

const config = new CommunicatorConfiguration(apiKey, apiSecret, "preprod.commerce-api.payone.com");
```

With the configuration you can create an API client for each reource you want to interact with. For example to create a commerce case you can use the `CommerceCaseApiClient`.


```ts
const commerceCaseClient = new CommerceCaseApiClient(config);
```

All payloads and reponses are availabe as ts interfaces exported from this library.
For example, to create an empty commerce case you can pass an object with the `CreateCommerceCaseRequest` interface:


```ts
const createCommerceCaseRequest: CreateCommerceCaseRequest = {};

const createCommerceCaseResponse: CreateCommerceCaseResponse = commerceCaseClient.createCommerceCaseRequest('merchant_id', createCommerceCaseRequest);
```

The models directly map to the API as described in [PAYONE Commerce Platform API Reference](https://docs.payone.com/pcp/commerce-platform-api).


### Error Handling

When making a request any client may throw a `ApiException`. There two subtypes of this exception:

- `ApiErrorReponseException`: This exception is thrown when the API returns an well-formed error response. The given errors are deserialized into `APIError` objects which are availble via the `getErrors()` method on the exception. They usually contain useful information about what is wrong in your request or the state of the resource.
- `ApiResponseRetrievalException`: This exception is a catch-all exception for any error that cannot be turned into a helpful error response. This includes malformed responses or unknown responses.


### Client Side

For most [payment methods](https://docs.payone.com/pcp/commerce-platform-payment-methods) some information from the client is needed, e.g. payment information given by Apple when a payment via ApplePay suceeds. PAYONE provides client side SDKs which helps you interact the third party payment providers. You can find the SDKs under the [PAYONE GitHub organization](https://github.com/PAYONE-GmbH). Either way ensure to never store or even send credit card information to your server. The PAYONE Commerce Platform never needs access to the credit card information. The client side is responsible for safely retrieving a credit card token. This token must be used with this SDK.

### Apple Pay

When a client is successfully made a payment via ApplePay it receives a [ApplePayPayment](https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypayment). This structure is accessible as the `ApplePayPayment` class. You can use the `ApplePayTransformer` to map an `ApplePayPayment` to a `MobilePaymentMethodSpecificInput` which can be used for payment executions or order requests. The transformer has a static method `transformApplePayPaymentToMobilePaymentMethodSpecificInput()` which takes an `ApplePayPayment` and returns a `MobilePaymentMethodSpecificInput`. The transformer does not check if the response is complete, if anything is missing the field will be set to `undefined`.

### Run the example app

```sh
cd example-app
yarn
API_KEY=api_key API_SECRET=api_secret MERCHANT_ID=123 COMMERCE_CASE_ID=234 CHECKOUT_ID=345 yarn dev
npm i
API_KEY=api_key API_SECRET=api_secret MERCHANT_ID=123 COMMERCE_CASE_ID=234 CHECKOUT_ID=345 npm run dev
```

## Contributing
Expand Down Expand Up @@ -82,15 +134,15 @@ npm run coverage
git checkout -b release/0.1.0
```

- Run prepare-release.sh script to set correct version
- Apply versioning

```sh
./prepare-release.sh
npm version major|minor|patch
```

#### Changelog Generation with Conventional Changelog

After calling the `prepare_release.sh` script, it is recommended to manually trigger the changelog generation script (which uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)).
After versioning, it is recommended to manually trigger the changelog generation script (which uses [conventional-changelog](https://github.com/conventional-changelog/conventional-changelog)).

1. **Conventional Commit Messages**:

Expand Down
6 changes: 3 additions & 3 deletions src/transformer/applepay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { ApplePayPayment } from '../models/applepay/ApplePayPayment.js';
import type { MobilePaymentMethodSpecificInput } from '../models/MobilePaymentMethodSpecificInput.js';
import { ApplePayPaymentMethodType } from '../models/applepay/ApplePayPaymentMethodType.js';
import { Network } from '../models/Network.js';
import { applePayPaymentToMobilePaymentMethodSpecificInput } from '../transformer/applepay.js';
import { transformApplePayPaymentToMobilePaymentMethodSpecificInput } from '../transformer/applepay.js';

describe('applepay transformer', () => {
describe('applePayPaymentToMobilePaymentMethodSpecificInput', () => {
describe('transformApplePayPaymentToMobilePaymentMethodSpecificInput', () => {
test('converts a full ApplePayPayment correctly', () => {
const payment: ApplePayPayment = {
token: {
Expand Down Expand Up @@ -60,7 +60,7 @@ describe('applepay transformer', () => {
},
};

expect(applePayPaymentToMobilePaymentMethodSpecificInput(payment)).toEqual(expected);
expect(transformApplePayPaymentToMobilePaymentMethodSpecificInput(payment)).toEqual(expected);
});
});
});
2 changes: 1 addition & 1 deletion src/transformer/applepay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function versionFromString(value: string): ApplePaymentTokenVersion {
}
}

export function applePayPaymentToMobilePaymentMethodSpecificInput(
export function transformApplePayPaymentToMobilePaymentMethodSpecificInput(
payment: ApplePayPayment,
): MobilePaymentMethodSpecificInput {
return {
Expand Down

0 comments on commit 487c39f

Please sign in to comment.