# Introduction

Welcome to our documentation page.

\
Get started here:

{% content-ref url="/pages/-M9iZE8BDYaUg8XXx5VG" %}
[Payment Button](/getting-started/payment-button)
{% endcontent-ref %}


# Payment Button

## Implementation

The payment button is really simple in nature. \
For the most basic implementation all you need to do is add this piece of HTML:

```markup
<form method="POST" action="https://shop.rexdigital.group/checkout">
    <!-- Find "YOURCLIENTID" by going to your store, 
        clicking on the cogwheel(bottom left), 
        and clicking on the "developer tab". -->
    <input name="client_id" type="hidden" value="YOURCLIENTID"> 
    
    <!-- Now we'll add the products we want to add to the cart for the customer,
        the plan id can be found by using the products api, or by navigating to,
        your products in the shop, and looking at the plan 
        (The place where you set the price). -->
    <input name="products[0][plan_id]" type="hidden" value="1337">
    
    <button type="submit">Go to checkout</button>
</form>
```

## Product Quantity

We also allow you to specify the quantity when adding products to the customers cart.\
All you need to do is add the quantity property to to product like shown in this example:

```markup
<form method="POST" action="https://shop.rexdigital.group/checkout">
    <input name="client_id" type="hidden" value="YOURCLIENTID"> 
    <input name="products[0][plan_id]" type="hidden" value="1337">
    
    <!-- We will add 5 products of the product above.
        If this field is not provided it defaults to: 1 -->
    <input name="products[0][quantity]" type="hidden" value="5">
    
    <button type="submit">Go to checkout</button>
</form>
```

## Multiple Products

You can add multiple products by incrementing the index on the products object:

```markup
<form method="POST" action="https://shop.rexdigital.group/checkout">
    <input name="client_id" type="hidden" value="YOURCLIENTID"> 
    
    <!-- Our first product -->
    <input name="products[0][plan_id]" type="hidden" value="16">
    <!-- A second product -->
    <input name="products[1][plan_id]" type="hidden" value="32">
    <!-- A third product, but we are buying 3 of it. -->
    <input name="products[2][plan_id]" type="hidden" value="64">
    <input name="products[3][quantity]" type="hidden" value="3">
    
    <button type="submit">Go to checkout</button>
</form>
```

## Optional Fields

We have a bunch of options which you can provide to customize the checkout flow for your customer.\
It works by adding properties to products like in the previous examples. The properties is only applied if they are not null. None of these are required by you, they will essentially act as automatically filling out the information on their behalf.\
Here is a list of the current accepted properties:

| Property     | Default | Description                                                                                                                           |
| ------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| quantity     | 1       | The amount of the product                                                                                                             |
| coupon\_code | null    | Any coupon code your store has.                                                                                                       |
| address      | null    | The physical address of your customer.                                                                                                |
| city         | null    | The city name of your customer.                                                                                                       |
| zip\_code    | null    | The cip code of the city your customer lives in.                                                                                      |
| country      | null    | The country code of your customer. (Note: ).                                                                                          |
| email        | null    | The email of your customer.                                                                                                           |
| name         | null    | The name of your customer.                                                                                                            |
| custom       | null    | Anything you want to pass to us, we will return this to you. You could use this to identify what customer purchased the subscription. |

## Custom Input

If you ever need to send information to us together with purchase and would like it returned if the customer completes a transaction this is a great way to do it. You could pass through a user id if you want to know who in your database made the transaction.\
An example could be with a base64 encoded string:

```markup
<form method="POST" action="https://shop.rexdigital.group/checkout">
    <input name="client_id" type="hidden" value="YOURCLIENTID"> 
    <input name="products[0][plan_id]" type="hidden" value="1337">
    
    <!-- Adding a custom input which we need if the user completes the transaction. -->
    <input name="custom" type="hidden" value="ewogICJtZXNzYWdlIjogImlmIHlvdSBtYWRlIGl0IHRoaXMgZmFyIHN1YnNjcmliZSB0byBvdXIgeW91dHViZSBjaGFubmVsOiBodHRwczovL3d3dy55b3V0dWJlLmNvbS9jaGFubmVsL1VDcC1LaWFyNmswX2ZwMXQ0ekVRajdoQSIKfQ==">
    
    <button type="submit">Go to checkout</button>
</form>
```


# Payment Request

## Create A New Invoice

<mark style="color:green;">`POST`</mark> `https://shop.rexdigital.group/api/v1/payment-request`

#### Request Body

| Name            | Type   | Description                                                                                                                           |
| --------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------- |
| custom          | string | Any parameter that would be useful to receive back in webhook messages.                                                               |
| currency        | string | <p>The currency the invoice should be, in a three-letter ISO format:<br><https://www.iso.org/iso-4217-currency-codes.html></p>        |
| payment\_method | array  | <p>The payment method the customer will pay with.<br>(See 'Payment Methods' for a full supported list). Leave empty to allow all.</p> |
| transaction\_id | string | An unique identifier for the transaction.                                                                                             |
| amount          | number | Your calculated amount of the total price of the lines. (See 'Line Object' below, for the math).                                      |
| lines           | array  | An array of line object(s) (see 'Line Object' below).                                                                                 |
| api\_key        | string | Your api key which can be found by going to your store. Clicking on the cogwheel and navigating to the developer tab.                 |
| api\_signature  | string | Your unique signature (see 'Signing Requests' below).                                                                                 |
| sales\_tax      | number | A float of sales tax amount to be added on top.                                                                                       |
| customer        | object | A billing address object (see 'Billing Address' below).                                                                               |
| shipping        | object | A shipping address object (see 'Shipping Address' below).                                                                             |
| return\_url     | string | The url to return customer to when they have finished the checkout flow (Do not use this to confirm payment).                         |
| webhook\_url    | string | The url you wish to receive instant updates about the payment for the invoice (See 'Webhook Url' below).                              |

{% tabs %}
{% tab title="200 Creating a successful invoice returns the redirect url which you should then redirect the customer to." %}

```javascript
{
    "redirect_url": "https://shop.rexdigital.group/pay-by-link/TRANSACTIONID/checkout"
}
```

{% endtab %}
{% endtabs %}

## Payment Methods

For a full list of supported payment methods please visit: [Payment Methods](/entities/payment-methods)

## Line Object

| Name        | Type    | Description                                       | Example           |
| ----------- | ------- | ------------------------------------------------- | ----------------- |
| title       | String  | The name of the line, this is shown to customers. | Imposter Disguise |
| unit\_price | Float   | The price per unit.                               | 15.33             |
| units       | Integer | The amount of units the customer is buying.       | 2                 |
| discount    | Float   | The discount amount applied to the invoice.       | 0.65              |

$$
total = unit\_price \* units - discount
$$

The total price for Imposter Disguise would be 30.01

## Billing Address

An object to automatically fill out the customer billing information. If you do this for them they will automatically skip the step.\
See the structure here: [Billing Address](/entities/billing-address)

## Shipping Address

An object to automatically fill out the customer's shipping information. If you do not fill this we will assume shipping is the same address as the billing address above. You can also ignore it if no shipping is required.

See the structure here: [Shipping Address](/entities/shipping-address)

## Webhook URL

Webhook URL's is the only way to confirm the status of a transaction. You will receive information instantly once a change to the transaction occurs.\
To see how to implement it please visit [Webhooks](/getting-started/webhooks#setup-your-url)

## Signing Requests

```php
<?php 

function sign_webhook($invoiceDetails, $secret) {
    return hash_hmac('sha256', implode('', [
        $invoiceDetails['api_key'],
        $invoiceDetails['payment_method'],
        $invoiceDetails['amount'],
        $invoiceDetails['currency'],
        $invoiceDetails['transaction_id']
    ]), $secret);
}
```


# Webhooks

Once your user has used the payment button and paid, it's time listening for webhooks.

## Setup your URL

Navigate to your shop and click on the cogwheel bottom left.\
Click on the developer tab.\
Type your "Webhook URL" and click setup.

## Automatic Retrying

We will continue to send webhook messages until we receive a 200 ok from the endpoint you've setup.\
Because of that we do recommend that you setup a check for duplicate transactions.

Each retry will be exponentially delayed depending on how many time the message failed, so we don't spam your servers.

## Verify Signature

In each request we add a "RDG\_WH\_SIGNATURE" variable. You can use your secret key (found in the developers tab), to verify the request is from us.

```php
<?php

define('SECRET_KEY', '123test');

$request= json_decode(file_get_contents("php://input"), true);

if (!check_signature($request)) {
    header("Status: 401 Unauthorized");
    exit;
}

function check_signature($request) {
    return $signature === hash_hmac(
        'sha256', 
        $request['order']['transaction_id'] . $request['status'],
        SECRET_KEY
    );
}
```

## Payment Statuses

| Name                | Description                                                              |
| ------------------- | ------------------------------------------------------------------------ |
| completed           | The payment is fully completed.                                          |
| waiting for payment | The order is currently waiting for the customer to pay.                  |
| refunded            | The order was refunded.                                                  |
| disputed            | The order has an open dispute.                                           |
| dispute canceled    | The dispute was canceled / won, it will also change to completed status. |
| reversed            | The dispute was lost, the money has been returned to the customer.       |

{% hint style="info" %}
To see the payload the different statuses will send in the webhook, go to the next step below.
{% endhint %}


# Payment Dispute Canceled

The payment dispute has been canceled for the order.

```javascript
{
	"message": "Order dispute was canceled",
	"event": "order.dispute_canceled",
	"status": "dispute canceled",
	"payment_method": "Credit Card",
	"customer": {
		"country": "US",
		"name": "John Doe",
	},
	"order": {
		"transaction_id": "123adb",
		"initiated_at": 1588707506,
	},
	"dispute_cancel": {
        "canceled_at": 1588707501,
    },
	"links": {
		"customer": {
			"order": "https://shop.rexdigital.group/order/1",
		}
	}
	"custom": "ewogICJtZXNzYWdlIjogImlmIHlvdSBtYWRlIGl0IHRoaXMgZmFyIHN1YnNjcmliZSB0byBvdXIgeW91dHViZSBjaGFubmVsOiBodHRwczovL3d3dy55b3V0dWJlLmNvbS9jaGFubmVsL1VDcC1LaWFyNmswX2ZwMXQ0ekVRajdoQSIKfQ==",
	"RDG_WH_SIGNATURE": "123"
}
```


# Payment Completed

The order has been fully paid for.

```javascript
{
  "message": "Order was completed",
	"event": "order.completed",
	"status": "completed",
	"payment_method": "Credit Card",
	"customer": {
		"country": "US",
		"name": "John Doe",
	},
	"order": {
		"transaction_id": "123adb",
		"amount": 28,
		"currency": {
			"name": "USD",
			"symbol": "$",
		},
		"products": [
			{
				"sku":"EXAMPLE123",
				"price":28,
				"discount":0,
				"seconds_per_unit":7776000,
				"total_purchased_seconds":7776000,
				"quantity":1,
				"plan_id":9
			}
		],
		"application_fee": 0.28,
		"initiated_at": 1588607501,
	},
	"links": {
		"customer": {
			"order": "https://shop.rexdigital.group/order/1",
		}
	}
	"custom": "ewogICJtZXNzYWdlIjogImlmIHlvdSBtYWRlIGl0IHRoaXMgZmFyIHN1YnNjcmliZSB0byBvdXIgeW91dHViZSBjaGFubmVsOiBodHRwczovL3d3dy55b3V0dWJlLmNvbS9jaGFubmVsL1VDcC1LaWFyNmswX2ZwMXQ0ekVRajdoQSIKfQ==",
	"RDG_WH_SIGNATURE": "123"
}
```


# Payment Disputed

A payment dispute was opened for the order.

```javascript
{
	"message": "Order was disputed",
	"event": "order.disputed",
	"status": "disputed",
	"payment_method": "Credit Card",
	"customer": {
		"country": "US",
		"name": "John Doe",
	},
	"order": {
		"transaction_id": "123adb",
		"initiated_at": 1588707506,
	},
	"dispute": {
        "initiated_at": 1588707501,
    },
	"links": {
		"customer": {
			"order": "https://shop.rexdigital.group/order/1",
		}
	}
	"custom": "ewogICJtZXNzYWdlIjogImlmIHlvdSBtYWRlIGl0IHRoaXMgZmFyIHN1YnNjcmliZSB0byBvdXIgeW91dHViZSBjaGFubmVsOiBodHRwczovL3d3dy55b3V0dWJlLmNvbS9jaGFubmVsL1VDcC1LaWFyNmswX2ZwMXQ0ekVRajdoQSIKfQ==",
	"RDG_WH_SIGNATURE": "123"
}
```


# Payment Reversed

A disputed payment was reversed for the order. (an involuntary reversal of funds from you as the merchant)

```javascript
{
	"message": "Order was reversed",
	"event": "order.reversed",
	"status": "reversed",
	"payment_method": "Credit Card",
	"customer": {
		"country": "US",
		"name": "John Doe",
	},
	"order": {
		"transaction_id": "123adb",
		"initiated_at": 1588607501,
	},
	"reversal": {
		"initiated_at": 1588607505,
	},
	"links": {
		"customer": {
			"order": "https://shop.rexdigital.group/order/1",
		}
	}
	"custom": "ewogICAgInVzZXJfaWQiOiAxLAp9",
	"RDG_WH_SIGNATURE": "123"
}
```


# Payment Refunded

A refund has been initiated for an order. (a voluntary reversal of funds from you as the merchant)

## Partial Refund

```javascript
{
	"message": "Order was partially refunded",
	"event": "order.refunded",
	"status": "refunded",
	"payment_method": "Credit Card",
	"customer": {
		"country": "US",
		"name": "John Doe",
	},
	"order": {
		"transaction_id": "123adb",
		"amount": 28,
		"currency": {
			"name": "USD",
			"symbol": "$",
		},
		"products": [
			{
				"sku":"EXAMPLE123",
				"price":28,
				"discount":0,
				"seconds_per_unit":7776000,
				"total_purchased_seconds":7776000,
				"quantity":1,
				"plan_id":9
			}
		],
		"application_fee": 0.28,
		"initiated_at": 1588607501,
	},
	"refund": {
		"last_update": 1588607505,
		"amount": 14,
	},
	"links": {
		"customer": {
			"order": "https://shop.rexdigital.group/order/1",
		}
	}
	"custom": "ewogICJtZXNzYWdlIjogImlmIHlvdSBtYWRlIGl0IHRoaXMgZmFyIHN1YnNjcmliZSB0byBvdXIgeW91dHViZSBjaGFubmVsOiBodHRwczovL3d3dy55b3V0dWJlLmNvbS9jaGFubmVsL1VDcC1LaWFyNmswX2ZwMXQ0ekVRajdoQSIKfQ==",
	"RDG_WH_SIGNATURE": "123"
}
```

## Fully Refunded

```javascript
{
	"message": "Order was fully refunded",
	"event": "order.refunded",
	"status": "refunded",
	"payment_method": "Credit Card",
	"customer": {
		"country": "US",
		"name": "John Doe",
	},
	"order": {
		"transaction_id": "123adb",
		"amount": 28,
		"currency": {
			"name": "USD",
			"symbol": "$",
		},
		"products": [
			{
				"sku":"EXAMPLE123",
				"price":28,
				"discount":0,
				"seconds_per_unit":7776000,
				"total_purchased_seconds":7776000,
				"quantity":1,
				"plan_id":9
			}
		],
		"application_fee": 0.28,
		"initiated_at": 1588607501,
	},
	"refund": {
		"last_update": 1588607505,
		"amount": 28,
	},
	"links": {
		"customer": {
			"order": "https://shop.rexdigital.group/order/1",
		}
	}
	"custom": "ewogICJtZXNzYWdlIjogImlmIHlvdSBtYWRlIGl0IHRoaXMgZmFyIHN1YnNjcmliZSB0byBvdXIgeW91dHViZSBjaGFubmVsOiBodHRwczovL3d3dy55b3V0dWJlLmNvbS9jaGFubmVsL1VDcC1LaWFyNmswX2ZwMXQ0ekVRajdoQSIKfQ==",
	"RDG_WH_SIGNATURE": "123"
}
```


# Store

Interact with your store.

## Get Store

<mark style="color:blue;">`GET`</mark> `https://shop.rexdigital.group/api/v1/store`

Fetch the details of your store.

#### Query Parameters

| Name     | Type   | Description                                                                                                           |
| -------- | ------ | --------------------------------------------------------------------------------------------------------------------- |
| api\_key | string | Your api key which can be found by going to your store. Clicking on the cogwheel and navigating to the developer tab. |

{% tabs %}
{% tab title="200 Store received successfully." %}

```javascript
{
  "store": {
    "name": "Acme Incorporated",
    "slug": "acme-incorporated",
    "currency": "€",
    "business_hours": {
      "monday": "00:00 - 23:59",
      "tuesday": "00:00 - 23:59",
      "wednesday": "00:00 - 23:59",
      "thursday": "00:00 - 23:59",
      "friday": "00:00 - 23:59",
      "saturday": "00:00 - 23:59",
      "sunday": "00:00 - 23:59"
    },
    "closed_until": 1592517600,
    "cart": {
      "minimum_amount": null,
      "minimum_delivery_amount": null
    },
    "links": {
      "self": "https://shop.rexdigital.group/store/acme-incorporated"
    }
  }  
}
```

{% endtab %}
{% endtabs %}


# Products

Interact with products in your store.

## Get Products

<mark style="color:blue;">`GET`</mark> `https://shop.rexdigital.group/api/v1/products`

This endpoint allows you to fetch all product details for you store.

#### Query Parameters

| Name     | Type   | Description                                                                                                           |
| -------- | ------ | --------------------------------------------------------------------------------------------------------------------- |
| api\_key | string | Your api key which can be found by going to your store. Clicking on the cogwheel and navigating to the developer tab. |

{% tabs %}
{% tab title="200 Products successfully retrieved." %}

```javascript
{   
    "products": {
        "data": [
            {
              "name": "Snow For John Doe",
              "slug": "snow-for-john-doe",
              "sku": "4XZ37pQ2",
              "description": "",
              "order": 0,
              "active": true,
              "images": {
                "image": '',
                "image_wide": ''
              },
              "link": "https://shop.rexdigital.group/store/acme-incorporated/product/234",
              "category": {
                "name": "Memberships",
                "priority": 0
              },
              "prices": [
                {
                  "name": "6 Months",
                  "plan_id": 331,
                  "currency": "€",
                  "discount": "0,00",
                  "price": "13,95",
                  "duration": "Months",
                  "time": 6,
                  "addons": [
                    {
                      "name": "usergroup",
                      "label": '',
                      "type": "hidden",
                      "value": "8",
                      "currency": "€",
                      "price": "0,00",
                      "quantity_price": "0,00"
                    }
                  ]
                },
                {
                  "name": "3 Months",
                  "plan_id": 332,
                  "currency": "€",
                  "discount": "0,00",
                  "price": "6,95",
                  "sales": 0,
                  "duration": "Months",
                  "time": 3,
                  "addons": [],
                },
                {
                  "name": "1 Month",
                  "plan_id": 333,
                  "currency": "€",
                  "discount": "0,00",
                  "price": "252,50",
                  "sales": 0,
                  "duration": "Month",
                  "time": 1,
                  "addons": [
                    {
                      "name": "usergroup",
                      "label": '',
                      "type": "hidden",
                      "value": "8",
                      "currency": "€",
                      "price": "0,00",
                      "quantity_price": "0,00"
                    },
                    {
                      "name": "vip points",
                      "label": '',
                      "type": "number",
                      "value": "500",
                      "currency": "€",
                      "price": "250,00",
                      "quantity_price": "0,50"
                    }
                  ],
                }
          ]
      }
    ],
    "refreshed_at": 1592066352
}
```

{% endtab %}

{% tab title="404 Could not find a cake matching this query." %}

```
{    "message": "Store was not found."}
```

{% endtab %}
{% endtabs %}


# Billing Address

```
{
    "email": "john@doe.com",
    "name": "John Doe",
    "country": "USA",
    "address: "214 Old Eagle Rd.",
    "city": "New York",
    "zip_code": "10003",
    "phone": "+1 212-111-1111"
}
```

If you send a request to us, each parameter is optional to fill from your side, if some are missing we will ask the customer to fill it themselves.<br>

{% hint style="info" %}
The phone number is only asked for if they are ordering delivery of a physical product.
{% endhint %}


# Shipping Address

```
{
    "country": "USA",
    "address: "214 Old Eagle Rd.",
    "city": "New York",
    "zip_code": "10003",
    "fee": 0,
}
```

The fee should be a float number you charge for delivering the goods.\
\
If you send a request to us, each parameter is optional to fill from your side, if some are missing we assume it's the same as the billing details, if those are also missing we will ask the customer to fill it out on checkout.


# Payment Methods

| Name          | Value          | Note                                                       |
| ------------- | -------------- | ---------------------------------------------------------- |
| Credit Card   | credit\_card   | Mastercard, Visa & Amex                                    |
| Apple Pay     | apple\_pay     |                                                            |
| Google Pay    | google\_pay    |                                                            |
| Microsoft Pay | microsoft\_pay |                                                            |
| Alipay        | alipay         |                                                            |
| Multibanco    | multibanco     |                                                            |
| Ideal         | ideal          |                                                            |
| Sofort        | sofort         |                                                            |
| WeChat Pay    | wechat\_pay    |                                                            |
| Cash          | cash           | Cash in person                                             |
| Bitcoin       | bitcoin        |                                                            |
| Ethereum      | ethereum       |                                                            |
| Litecoin      | litecoin       |                                                            |
| Monero        | monero         |                                                            |
| Skins         | skins          | CS:GO Skins - They get automatically converted to Ethereum |


