Build Widget
Tokidoki API is for implementing subscription solution when product information is stored in Merchant Area Tokidoki section.
Please pass X-ApiKey
through HttpHeader
, the value is Project Key
,which can be found in Merchant Area.
Parameters
Name | Description |
---|---|
key required string |
The project key which can be found in Merchant Area→ My Projects. |
user_email required string |
Email of the end-user in your system. |
package_id required int |
If you use stored package, It can be found in Merchant Area–>Tokidoki–>Packages section It’s not required if request already contains package_sku_id |
package_sku_id required varchar |
Each package will be identified by an unique SKU ID. This is the SKU ID that you already inputted when you setup your package in Tokidoki section It’s not required if request already contains package_id |
custom optional array |
Refer to more optional parameters for extra needs or user profile parameters for risk scoring. |
tokidoki required boolean |
If you would like to flexible subscription, You must add ‘tokidoki’ parameter with value 1 . |
Endpoint
POST https://api.paymentwall.com/developers/tokidoki-api/widget-url
Sample Request for stored package
<?php
require_once('path/to/lib/paymentwall.php');
$key = 'YOUR_PROJECT_KEY';
$params = [
'user_email' => 'YOUR_EMAIL@email.com',
'package_id' => '29',
'custom' => [
'success_url' => 'https://www.xxx.com',
'failure_url' => 'https://www.yyy.com'
]
];
$curlOptions = [
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'X-ApiKey:' . $key
],
CURLOPT_POSTFIELDS => json_encode($params)
];
$endpoint = 'https://api.paymentwall.com/developers/tokidoki-api/widget-url';
$curl = curl_init();
curl_setopt_array($curl, $curlOptions);
curl_setopt($curl, CURLOPT_URL, $endpoint);
$content = curl_exec($curl);
curl_close($curl);
$response = json_decode($content, true);
if ($response['success'] == 1) {
echo $response['data'] . PHP_EOL;
} else {
echo $response['error'] . PHP_EOL;
}
?>
Sample Request for flexible package
<?php
require_once("/path/to/lib/paymentwall.php");
Paymentwall_Config::getInstance()->set(array(
'api_type' => Paymentwall_Config::API_GOODS,
'public_key' => 'YOUR_PROJECT_KEY',
'private_key' => 'YOUR_SECRET_KEY'
));
$productParams = [
'amount' => '1',
'currencyCode' => 'USD',
'name' => 'PRODUCT_NAME',
'productId' => 'PRODUCT_ID',
'productType' => 'subscription',
'periodLength' => '2',
'periodType' => 'month',//period type: day, week, month
'recurring' => '1'
];
$extraParams = [
'tokidoki' => '1',
'email' => 'user@hostname.com'
];
$product = new Paymentwall_Product(
$productParams['productId'],
$productParams['amount'],
$productParams['currencyCode'],
$productParams['name'],
$productParams['productType'],
$productParams['periodLength'],
$productParams['periodType'],
$productParams['recurring']
);
$widget = new Paymentwall_Widget(
'user@hostname.com', // uid
'p1', // widget
[$product],
$extraParams
);
echo $widget->getHtmlCode();
?>