# Integrate with PHP SDK

## Prerequisites

* PHP 5.6 or above
* [API credentials](https://indodana.gitbook.io/indodana-paylater/integrations/direct-api#preparation)
* [Composer](https://getcomposer.org/download/)

## Installation and Usage

Integrating with the PHP SDK requires two steps:

1. Install the SDK in your project
2. Initialize the SDK in your application&#x20;

### Step 1:  Install the SDK

#### Install via Composer

To install the SDK, use `composer`:

```bash
$ composer require indodana-finance/indodana-paylater-sdk
```

Include the SDK into your PHP file using the autoloader:

```php
<?php

require('<YOUR_PROJECT_DIRECTORY>/vendor/autoload.php');
```

### Step 2: Initialize the SDK

Usage:

```php
<?php

require('<YOUR_PROJECT_DIRECTORY>/vendor/autoload.php');

use Indodana\Indodana;

$indodana = new Indodana([
    'apiKey' => '<YOUR_API_KEY>',
    'apiSecret' => '<YOUR_API_SECRET>',
    'environment' => 'PRODUCTION' // Optional. Possible value: 'SANDBOX', 'PRODUCTION'. If not set, will default to 'SANDBOX'
]);
```

## Use Case

### Get Installment Options

Example:

```php
<?php

require('<YOUR_PROJECT_DIRECTORY>/vendor/autoload.php');

use Indodana\Indodana;

$indodana = new Indodana([
    'apiKey' => '<YOUR_API_KEY>',
    'apiSecret' => '<YOUR_API_SECRET>',
    'environment' => 'PRODUCTION'
]);

$installmentOptions = $indodana->getInstallmentOptions([
    'amount' => 412000,
    'items' => [
    [
          'id' => 'MAC1',
          'name' => 'MacBook Pro',
          'category' => '<ITEM-CATEGORY>',
          'price' => 406000,
          'quantity' => 1,
          'parentType' => 'SELLER',
          'parentId' => '32b500ae-6a95-11ea-bc55-0242ac130003'
    ],
    [
        'id' => 'shippingfee',
        'name' => 'Shipping Fee for Order KXA-1001',
        'category' => '<ITEM-CATEGORY>',
        'price' => 10000,
        'quantity' => 1,
        'parentType' => 'SELLER',
        'parentId' => '32b500ae-6a95-11ea-bc55-0242ac130003'
    ],
    [
        'id' => 'taxfee',
        'name' => 'Tax Fee for Order KXA-1001',
        'category' => '<ITEM-CATEGORY>',
        'price' => 20000,
        'quantity' => 1,
        'parentType' => 'SELLER',
        'parentId' => '32b500ae-6a95-11ea-bc55-0242ac130003'
    ],
    [
        'id' => 'discount',
        'name' => 'Discount for Order KXA-1001',
        'category' => '<ITEM-CATEGORY>',
        'price' => 24000,
        'quantity' => 1,
        'parentType' => 'SELLER',
        'parentId' => '32b500ae-6a95-11ea-bc55-0242ac130003'
    ]
    ]
]);
```

The array inside `getInstallmentOptions` method follows [Get Installment Options request body](https://indodana.gitbook.io/indodana-paylater/integrations/api-reference#get-installment-options-1) format.

The value of `$installmentOptions` follows [Get Installment Options response body](https://indodana.gitbook.io/indodana-paylater/integrations/api-reference#get-installment-options-1) format.

### Checkout

Example:

```php
<?php

require('<YOUR_PROJECT_DIRECTORY>/vendor/autoload.php');

use Indodana\Indodana;

$indodana = new Indodana([
    'apiKey' => '<YOUR_API_KEY>',
    'apiSecret' => '<YOUR_API_SECRET>',
    'environment' => 'PRODUCTION'
]);

$result = $indodana->checkout([
    'transactionDetails' => [
        'merchantOrderId' => 'KXA-1001',
        'amount' => 412000,
        'items' => [
            [
                'id' => 'MAC1',
                'name' => 'MacBook Pro',
                'category' => '<ITEM-CATEGORY>',
                'price' => 406000,
                'quantity' => 1,
                'parentType' => 'SELLER',
                'parentId' => '32b500ae-6a95-11ea-bc55-0242ac130003'
            ],
            [
                'id' => 'shippingfee',
                'name' => 'Shipping Fee for Order KXA-1001',
                'category' => '<ITEM-CATEGORY>',
                'price' => 10000,
                'quantity' => 1,
                'parentType' => 'SELLER',
                'parentId' => '32b500ae-6a95-11ea-bc55-0242ac130003'
            ],
            [
                'id' => 'taxfee',
                'name' => 'Tax Fee for Order KXA-1001',
                'category' => '<ITEM-CATEGORY>',
                'price' => 20000,
                'quantity' => 1,
                'parentType' => 'SELLER',
                'parentId' => '32b500ae-6a95-11ea-bc55-0242ac130003'
            ],
            [
                'id' => 'discount',
                'name' => 'Discount for Order KXA-1001',
                'category' => '<ITEM-CATEGORY>',
                'price' => 24000,
                'quantity' => 1,
                'parentType' => 'SELLER',
                'parentId' => '32b500ae-6a95-11ea-bc55-0242ac130003'
            ]
        ]
    ],
    'customerDetails' => [
        'firstName' => 'John',
        'lastName' => 'Doe',
        'email' => 'johndoe@gmail.com',
        'phone' => '081277770000'
    ],
    'sellers' => [
        [
            'id' => '32b500ae-6a95-11ea-bc55-0242ac130003',
            'name' => 'Mac Official Store',
            'email' => 'admin@macofficialstore.com',
            'url' => 'www.macofficialstore.com',
            'address' => [
                'firstName' => 'Mac Official Store',
                'lastName' => '',
                'address' => 'Jl. M.H Thamrin Boulevard No.22',
                'city' => 'Tangerang',
                'postalCode' => '15811',
                'phone' => '081299991111',
                'countryCode' => 'IDN'
            ]
        ]
    ],
    'billingAddress' => [
        'firstName' => 'John',
        'lastName' => 'Doe',
        'address' => 'Jl. Kyai H. Syahdan No.9, Kel.Palmerah, Kec. Palmerah',
        'city' => 'Jakarta Barat',
        'postalCode' => '11480',
        'phone' => '081277770000',
        'countryCode' => 'IDN'
    ],
    'shippingAddress' => [
        'firstName' => 'John',
        'lastName' => 'Doe',
        'address' => 'Jl. Kyai H. Syahdan No.9, Kel.Palmerah, Kec. Palmerah',
        'city' => 'Jakarta Barat',
        'postalCode' => '11480',
        'phone' => '081277770000',
        'countryCode' => 'IDN'
    ],
    'paymentType' => '30_days',
    'approvedNotificationUrl' => 'https://macofficialstore.com/indodanapayment/checkout/approve',
    'cancellationRedirectUrl' => 'https://macofficialstore.com/indodanapayment/checkout/cancel',
    'backToStoreUrl' => 'https://macofficialstore.com/indodanapayment/checkout/success'
]);
```

The array inside `checkout` method follows [Checkout request body](https://indodana.gitbook.io/indodana-paylater/integrations/api-reference#purchase-transaction-checkout-1) format.

The value of `$result` follows [Checkout response body](https://indodana.gitbook.io/indodana-paylater/integrations/api-reference#purchase-transaction-checkout-1) format.

### Check Transaction Status

Example:

```php
<?php

require('<YOUR_PROJECT_DIRECTORY>/vendor/autoload.php');

use Indodana\Indodana;

$indodana = new Indodana([
    'apiKey' => '<YOUR_API_KEY>',
    'apiSecret' => '<YOUR_API_SECRET>',
    'environment' => 'PRODUCTION'
]);

$result = $indodana->checkTransactionStatus([
    'merchantOrderId' => 'KXA-1001'
]);
```

The array inside `checkTransactionStatus` method follows [Check Transaction Status query params](https://indodana.gitbook.io/indodana-paylater/integrations/api-reference#check-transaction-status-1) format.

The value of  `$result` follows [Check Transaction Status response body](https://indodana.gitbook.io/indodana-paylater/integrations/api-reference#check-transaction-status-1) format.

### Order Cancellation / Refund

Example:

```php
<?php

require('<YOUR_PROJECT_DIRECTORY>/vendor/autoload.php');

use Indodana\Indodana;

$indodana = new Indodana([
    'apiKey' => '<YOUR_API_KEY>',
    'apiSecret' => '<YOUR_API_SECRET>',
    'environment' => 'PRODUCTION'
]);

$result = $indodana->refund([
    'refundId' => 'RFA-1001',
    'merchantOrderId' => 'KXA-1001',
    'cancellationAmount' => 412000,
    'cancellationReason' => 'MAC1 stock is already empty',
    'cancelledBy' => 'Mac Admin',
    'cancellationDate' => '2020-03-19T09:53:00+07:00'
]);
```

The array inside `refund` method follows [Order Cancellation / Refund request body](https://indodana.gitbook.io/indodana-paylater/integrations/api-reference#purchase-transaction-cancellation-refund-1) format.

The value of  `$result` follows [Order Cancellation / Refund response body](https://indodana.gitbook.io/indodana-paylater/integrations/api-reference#purchase-transaction-cancellation-refund-1) format.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.indodana.id/indodana-paylater/integration/integrate-with-php-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
