# Technical documentation

## Overview

This chapter provides the instruction of the integration with the solution and with it's methods. Prior to using this solution the Customer have to proceed onboarding process. To create account please contact with support.

## Integration

This section describes how to integrate the solution using the SDK provided by Verestro. The merchant-paytool.js is a JavaScript-based client-side SDK. The SDK adds MerchantPayTool class to the global JavaScript scope which can be further instantiated to start Donate Widget’s payment process. Alternatively, it also defines a custom element called merchant-paytool for a more straightforward, plug-and-play solution.

An optional step is to send a transaction status notification to the Merchant Server. Details of the notification are described in the [<span style="text-decoration: underline;"><span style="color: #000000; text-decoration: underline;">postback</span></span>](https://developer.verestro.com/books/donate-widget/page/technical-documentation#bkmrk-doda%C4%86-opis-metody-po) section.

Additionally, the PayTool SDK provides a method that allows you to "<span style="text-decoration: underline;">[<span style="color: #000000; text-decoration: underline;">get transaction details</span>](https://developer.verestro.com/books/donate-widget/page/technical-documentation#bkmrk-get-transaction-deta)</span>" using "*transactionId"* parameter.

### API Reference

Initialization Add the following script to your website:

**Test environment:**

```JavaScript
<script type="module" src="https://merchant-paytool.verestro.dev/merchant-paytool.js"></script>
```

**Production environment:**

```JavaScript
<script type="module" src="https://merchant-paytool.verestro.com/merchant-paytool.js"></script>
```

<p class="callout info">The **type="module"** attribute is currently required, because the SDK utilizes modern JavaScript code splitting syntax.</p>

### SDK Methods

<table border="1" cellpadding="1" cellspacing="0" id="bkmrk-abbreviation-descrip" style="width: 904px;" width="712"><tbody><tr valign="TOP"><td bgcolor="#1C1E3F" style="width: 807px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**init**</span>

</td></tr><tr valign="TOP"><td style="width: 807px;" width="353">(class approach only)  
  
Starts PayTool's payment process using the provided data.

After successful initialization, resolves a promise and redirects to PayTool's website.

Rejects a promise if any error occurs.

</td></tr><tr valign="TOP"><td bgcolor="#1C1E3F" style="width: 807px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Parameters**</span>

</td></tr><tr valign="TOP"><td style="width: 807px;" width="353"><span style="font-family: Lato;">data</span>

<span style="font-family: Lato;">initData</span>

</td></tr><tr valign="TOP"><td bgcolor="#1C1E3F" style="width: 807px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Returns**</span>

</td></tr><tr valign="TOP"><td style="width: 807px;" width="353"><span style="font-family: Lato;">Promise&lt;void&gt;</span>

</td></tr></tbody></table>

### Interfaces

Data object passed to PayTool's backend API.

<table class="tableblock frame-all grid-all spread" id="bkmrk-initdata-name-type-d" style="width: 100%; height: 350.297px;"><colgroup><col style="width: 20.3927%;"></col><col style="width: 9.14999%;"></col><col style="width: 70.4574%;"></col></colgroup><thead><tr style="height: 22.3906px;"><td bgcolor="#1C1E3F" colspan="3" style="height: 22.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**initData**</span>

</td></tr><tr style="height: 35.3906px;"><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Name**</span>

</td><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Type**</span>

</td><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Description**</span>

</td></tr></thead><tbody><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">apiKey

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">string

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">Merchant identifier, given during onboarding.

</td></tr><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">amount

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">number

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">Transaction amount in the lowest unit of money, fe. cents for USD.

</td></tr><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">currency

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">string

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">Transaction currency code.

</td></tr><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">description

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">string

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">Short description of transaction.

</td></tr><tr style="height: 80.1719px;"><td class="tableblock halign-left valign-top" style="height: 80.1719px;">redirectUrls

</td><td class="tableblock halign-left valign-top" style="height: 80.1719px;">object

</td><td class="tableblock halign-left valign-top" style="height: 80.1719px;">Optional return url object. If not provided, urls from merchant’s config will be used instead.PayTool might append additional query parameters to the urls, fe. a transaction identifier.

</td></tr><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">redirectUrls.successUrl

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">string

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">The url where users will be redirected after a successful payment.

</td></tr><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">redirectUrls.failureUrl

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">string

</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">The url where users will be redirected after a failed payment.

</td></tr></tbody></table>

### Examples

The SDK offers different ways to initialize a payment. It can do most of the heavy lifting by itself, including UI, but it also exposes a lower-end API to let you customize your UX.

### Class approach

Angular

```JavaScript
{
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: '<button (click)="onClick()">Pay</button>',
})
export class AppComponent {
  payTool = new MerchantPayTool();

  onClick() {
    this.payTool
      .init({
        apiKey: 'YOUR_API_KEY',
        amount: 9999,
        currency: 'CURRENCY_CODE',
        description: 'TRANSACTION_DESCRIPTION',
        redirectUrls: {
          successUrl: 'YOUR_SUCCESS_URL',
          failureUrl: 'YOUR_FAILURE_URL'
        }
      })
      .catch(console.log);
  }
}
} 
```

React

```JavaScript
export const App = () => {
  const payTool = new MerchantPayTool();
  return (
    <button
      onClick={() => {
        payTool
          .init({
            apiKey: 'YOUR_API_KEY',
            amount: 9999,
            currency: 'CURRENCY_CODE',
            description: 'TRANSACTION_DESCRIPTION',
            redirectUrls: {
              successUrl: 'YOUR_SUCCESS_URL',
              failureUrl: 'YOUR_FAILURE_URL'
            }
          })
          .catch(console.log);
      }}>
      Pay
    </button>
  );
};
```

Plain JavaScript

```JavaScript

<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script
      type="module"
      src="https://merchant-paytool.verestro.com/merchant-paytool.js"
    ></script>
  </head>
  <body>
    <button id="pay-btn">Pay</button>
    <script>
      var payButton = document.getElementById('pay-btn');
      payButton.addEventListener('click', function () {
        var payTool = new MerchantPayTool();
        payTool
          .init({
            apiKey: 'YOUR_API_KEY',
            amount: 9999,
            currency: 'CURRENCY_CODE',
            description: 'TRANSACTION_DESCRIPTION',
            redirectUrls: {
              successUrl: 'YOUR_SUCCESS_URL',
              failureUrl: 'YOUR_FAILURE_URL'
            }
          })
          .catch(console.log);
      });
    </script>
  </body>
</html>
```

### Web component approach

This approach focuses on modern solutions to help your integrate with PayTool as fast as possible and keep your code clean, providing a pre-built "Click to Pay" button. The component accepts data as Init Data, similarly to the [<span style="text-decoration: underline;">init</span>](https://merchant-beta.upaidtest.pl/champion/docs/paytool.html#init) method.

Angular

```JavaScript
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: '<merchant-paytool [data]="data"></merchant-paytool>',
})
export class AppComponent {
  data = {
    apiKey: 'YOUR_API_KEY',
    amount: 9999,
    currency: 'CURRENCY_CODE',
    description: 'TRANSACTION_DESCRIPTION',
    redirectUrls: {
      successUrl: 'YOUR_SUCCESS_URL',
      failureUrl: 'YOUR_FAILURE_URL',
    },
  };
}
```

React@^18

```JavaScript
export const App = () => {
  return (
    <merchant-paytool
      ref={el => {
        if (el) {
          el.data = {
            apiKey: 'YOUR_API_KEY',
            amount: 9999,
            currency: 'CURRENCY_CODE',
            description: 'TRANSACTION_DESCRIPTION',
            redirectUrls: {
              successUrl: 'YOUR_SUCCESS_URL',
              failureUrl: 'YOUR_FAILURE_URL'
            }
          };
        }
      }}
    />
  );
};
```

React@experimental

```JavaScript
export const App = () => {
  return (
    <merchant-paytool
      data={{
        apiKey: 'YOUR_API_KEY',
        amount: 9999,
        currency: 'CURRENCY_CODE',
        description: 'TRANSACTION_DESCRIPTION',
        redirectUrls: {
          successUrl: 'YOUR_SUCCESS_URL',
          failureUrl: 'YOUR_FAILURE_URL'
        }
      }}
    />
  );
};
```

Plain JavaScript

```JavaScript
export const App = () => {
  return (
    <merchant-paytool
      data={{
        apiKey: 'YOUR_API_KEY',
        amount: 9999,
        currency: 'CURRENCY_CODE',
        description: 'TRANSACTION_DESCRIPTION',
        redirectUrls: {
          successUrl: 'YOUR_SUCCESS_URL',
          failureUrl: 'YOUR_FAILURE_URL'
        }
      }}
    />
  );
};
```

<p class="callout info">In case of questions regarding the integration, Verestro actively supports Customer in the implementation.</p>

## Postbacks

This section describes the method that allows Customer to receive notifications after every donation made. If Customer wants to handle notifications after transactions Customer must create HTTP POST endpoint which will accept requests in format JSON. If this option is enabled, the Donate Widget API will send information about the donation made to the endpoint provided by the Customer.

<p class="callout warning">This feature is optional but we strongly recommend using it. Without this method, the Customer will not receive any information whether the donation was successful or not.</p>

<table border="1" id="bkmrk-post-%5Bbase-url%5D%2Fweb%2F" style="border-collapse: collapse; width: 100%; height: 29.7969px;"><tbody><tr style="height: 29.7969px;"><td style="width: 99.8765%; height: 29.7969px;"><span style="color: #843fa1;">*POST site.customer.com/notifications*</span></td></tr></tbody></table>

Request body:

```JSON
POST site.customer.com/notifications HTTP/1.1
Content-Type: application/json
Content-Length: 265

{
  "transactionId": "3a1e9961-75bc-4279-8791-033c180fa239",
  "status": "DEPOSITED",
  "amount": 100,
  "currency": "USD",
  "description": "description"
}
```

<table class="tableblock frame-all grid-all spread" id="bkmrk-request-headers%3A-typ" style="width: 100%; height: 107.156px;"><colgroup><col style="width: 20.3956%;"></col><col style="width: 16.0692%;"></col><col style="width: 13.7206%;"></col><col style="width: 49.8146%;"></col></colgroup><thead><tr style="height: 35.3906px;"><td bgcolor="#1C1E3F" colspan="4" style="height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Request headers:**</span>

</td></tr><tr style="height: 35.3906px;"><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Type**</span>

</td><td bgcolor="#1C1E3F" style="width: 355.5px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Value**</span>

</td><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Constraints**</span>

</td><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Description**</span>

</td></tr></thead><tbody><tr style="height: 36.375px;"><td class="tableblock halign-left valign-top">Content-Type

</td><td class="tableblock halign-left valign-top">application/json

</td><td class="tableblock halign-left valign-top">Required

</td><td class="tableblock halign-left valign-top">Content type of the request.

</td></tr></tbody></table>

<table class="tableblock frame-all grid-all spread" id="bkmrk-request-fields%3A-type" style="width: 100%; height: 107.156px;"><colgroup><col style="width: 20.3956%;"></col><col style="width: 16.0692%;"></col><col style="width: 13.7206%;"></col><col style="width: 49.8146%;"></col></colgroup><thead><tr style="height: 35.3906px;"><td bgcolor="#1C1E3F" colspan="4" style="height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Request fields:**</span>

</td></tr><tr style="height: 35.3906px;"><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Type**</span>

</td><td bgcolor="#1C1E3F" style="width: 355.5px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Value**</span>

</td><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Constraints**</span>

</td><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Description**</span>

</td></tr></thead><tbody><tr><td class="tableblock halign-left valign-top">transactionId

</td><td class="tableblock halign-left valign-top">String

</td><td class="tableblock halign-left valign-top">Required

</td><td class="tableblock halign-left valign-top">Unique Id of transaction.

</td></tr><tr><td class="tableblock halign-left valign-top">status

</td><td class="tableblock halign-left valign-top">String

</td><td class="tableblock halign-left valign-top">Required

</td><td class="tableblock halign-left valign-top">Transaction status. **AUTHORIZED**, **DEPOSITED**, **FAILED**, **UNKNOWN**,

**REFUNDED**, **REVERSED.**

</td></tr><tr><td class="tableblock halign-left valign-top">amount

</td><td class="tableblock halign-left valign-top">Number

</td><td class="tableblock halign-left valign-top">Required

</td><td class="tableblock halign-left valign-top">Amount for transaction (minor units of currency).

</td></tr><tr><td class="tableblock halign-left valign-top">currency

</td><td class="tableblock halign-left valign-top">String

</td><td class="tableblock halign-left valign-top">Required

</td><td class="tableblock halign-left valign-top">Currency of given amount.

</td></tr><tr><td class="tableblock halign-left valign-top">description

</td><td class="tableblock halign-left valign-top">String

</td><td class="tableblock halign-left valign-top">Required

</td><td class="tableblock halign-left valign-top">Simple description of transaction.</td></tr></tbody></table>

Response status: HTTP/1.1 <span class="hljs-number">200</span> OK

Example cURL:

```JSON
$ curl 'https://site.customer.com/notifications' -i -u 'login:password' -X POST -H 'Content-Type: application/json' -d '{

  	"transactionId": "387cd038-fa39-40e1-a6ac-0d610b594787",
    "status": "DEPOSITED",
  	"amount": 100,
  	"currency": "USD",
  	"description": "description",
}'
```

## Get transaction details

<table border="1" id="bkmrk-get-%5Bbase-url%5D%2Ftrans" style="border-collapse: collapse; width: 100%; height: 29.7969px;"><tbody><tr style="height: 29.7969px;"><td style="width: 99.8765%; height: 29.7969px;"><span style="color: #843fa1;">***GET \[base-url\]/transactions/{{transactionId}}***</span>

</td></tr></tbody></table>

Method allows getting transaction details using "*transactionId"*. Method is protected by BasicAuth of the Customer.

Request:

```JSON
GET /champion/transactions/cd670818-dfbe-44fc-8948-8fbf8992d8d3 HTTP/1.1
Authorization: Basic bG9naW46cGFzc3dvcmQ=
Content-Type: application/json
Host: merchant.upaid.pl
```

<table class="tableblock frame-all grid-all spread" id="bkmrk-request-headers%3A-typ-1" style="width: 100%; height: 107.156px;"><colgroup><col style="width: 17.6761%;"></col><col style="width: 31.5242%;"></col><col style="width: 23.9764%;"></col><col style="width: 26.8232%;"></col></colgroup><thead><tr style="height: 35.3906px;"><td bgcolor="#1C1E3F" colspan="4" style="height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Request headers:**</span>

</td></tr><tr style="height: 35.3906px;"><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Type**</span>

</td><td bgcolor="#1C1E3F" style="width: 355.5px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Value**</span>

</td><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Constraints**</span>

</td><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Description**</span>

</td></tr></thead><tbody><tr style="height: 36.375px;"><td class="tableblock halign-left valign-top">Content-Type

</td><td class="tableblock halign-left valign-top">application/json

</td><td class="tableblock halign-left valign-top">Required

</td><td class="tableblock halign-left valign-top">Content type of the request.

</td></tr><tr><td class="tableblock halign-left valign-top">Authorization

</td><td class="tableblock halign-left valign-top">Basic bG9naW46cGFzc3dvcmQ=

</td><td class="tableblock halign-left valign-top">Required

</td><td class="tableblock halign-left valign-top">Basic Authorization token.

</td></tr></tbody></table>

Response body:

*HTTP Response - SUCCESS:*

```JavaScript
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Content-Length: 211

{
  "transactionId" : "cd670818-dfbe-44fc-8948-8fbf8992d8d3",
  "amount" : 100,
  "currency" : "PLN",
  "description" : "description",
  "bin" : "4442211",
  "lastFourDigits" : "1234",
  "status" : "DEPOSITED"
}
```

<table class="tableblock frame-all grid-all spread" id="bkmrk-request-fields%3A-type-0" style="width: 100%; height: 370.078px;"><colgroup><col style="width: 23.6094%;"></col><col style="width: 18.665%;"></col><col style="width: 57.7256%;"></col></colgroup><thead><tr style="height: 35.3906px;"><td bgcolor="#1C1E3F" colspan="3" style="height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Response fields:**</span>

</td></tr><tr style="height: 35.3906px;"><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Type**</span>

</td><td bgcolor="#1C1E3F" style="width: 355.5px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Value**</span>

</td><td bgcolor="#1C1E3F" style="width: 711px; height: 35.3906px;" width="353"><span style="font-family: Lato; color: #ecf0f1;">**Description**</span>

</td></tr></thead><tbody><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">transactionId</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">String</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">Unique Id of transaction.

</td></tr><tr style="height: 42.1719px;"><td class="tableblock halign-left valign-top" style="height: 42.1719px;">amount</td><td class="tableblock halign-left valign-top" style="height: 42.1719px;">Number</td><td class="tableblock halign-left valign-top" style="height: 42.1719px;">Transaction amount in pennies.

</td></tr><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">currency</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">String</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">Transaction currency.

</td></tr><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">description</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">String</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">Transaction description.

</td></tr><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">bin</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">String</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">Card bin.

</td></tr><tr style="height: 35.3906px;"><td class="tableblock halign-left valign-top" style="height: 35.3906px;">lastFourDigits</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">String</td><td class="tableblock halign-left valign-top" style="height: 35.3906px;">Card last four digits.

</td></tr><tr style="height: 80.1719px;"><td class="tableblock halign-left valign-top" style="height: 80.1719px;">status</td><td class="tableblock halign-left valign-top" style="height: 80.1719px;">String</td><td class="tableblock halign-left valign-top" style="height: 80.1719px;">Transaction Status. Possible values: DEPOSITED - transaction finished with success INITIALIZED\_3DS - transaction during processing FAILED - transaction failed.

</td></tr></tbody></table>

*Example cURL:*

```JavaScript
$ curl 'https://merchant.upaid.pl/champion/transactions/cd670818-dfbe-44fc-8948-8fbf8992d8d3' -i -u 'login:password' -X GET \
    -H 'Content-Type: application/json'
```

</body></html>