## LinkPay API

---

## Documentation & Release Notes
+ Full LinkPay API reference documentation: https://developer.evonetonline.com/reference
+ SDK reference documentation for Javascript: https://git.cardinfolink.net/evocloud/linkpay-api-sdk-javascript

## Support
If you have any questions regarding the SDK, provided examples or our services, please refer to https://developer.evonetonline.com/reference.

---

## Installation

``` bash
npm install linkpay-api
```

## Initialization

### Node

Using ES6 `import`
```typescript
import * as dotenv from 'dotenv'
import { Configuration, PaymentRequest, genUUIDWithoutDash, genYYYYMMDDThhmmsshh00 } from 'linkpay-api';
import LinkPayAPI  from 'linkpay-api';

dotenv.config()

async function main() {
    const returnUrl = `${process.env.LINKPAY_RETURNURL}`
    const currency = `${process.env.LINKPAY_CURRENCY}`
    const amount = `${process.env.LINKPAY_AMOUNT}`
    
    // Set configuration
    const configuration: Configuration = { baseUrl: `${process.env.LINKPAY_BASEURL}`, sid: `${process.env.LINKPAY_SID}`, signKey: `${process.env.LINKPAY_SIGNKEY}` }
    // Create a LinkPayAPI instance
    const linkpay = new LinkPayAPI(configuration)
    
    // Build a payment request
    const request = new PaymentRequest()
    request.returnUrl = returnUrl
    request.merchantOrderInfo = {
        merchantOrderID: genUUIDWithoutDash(),
        merchantOrderTime: genYYYYMMDDThhmmsshh00(),
    }

    request.transAmount = {
        currency,
        value: `${amount}`,
    }
    
    // Call the related LinkPay API method
    const response = await linkpay.payment(request)

    console.log(JSON.stringify(response))
}

// call
main()
```

With `require`
```js
exports.__esModule = true;
const LinkpayApi = require('linkpay-api')["default"];

const linkpayApi = new LinkpayApi(configuration);
```

### Browser

Use `linkpay-api/dist/linkpay-api-sdk.browser.js` or `linkpay-api-sdk.browser.min.js` for the minified version.

### ES5 with Modules (CommonJS)

Import `linkpay-api/dist/index.js`.

### Types

- Typescript (`linkpay-api/dist/index.d.ts`)

## Examples
You can find sample workflow scripts in the examples and test folder.