PHP Backend Server

Configure Project

  1. Add the library module to your project using composer. Add the following in your composer.json
"require": {
    "dapi-co/dapi-php": "^1.0",
},

OR simply type this in your project folder.

composer require dapi-co/dapi-php
  1. Create a DapiClient with your App Secret.
// Assuming that Dapi library is already autoloaded. If not, manually include/require it here.
$dapiClient = new Dapi\DapiClient('APP_SECRET');

Configure SDK Server

  1. Follow the steps in Configure Project first in order to obtain and import the library.

  2. Or, you can use the handleSDKRequests function of the client instance inside an endpoint in your server. The library will add your app's appSecret to the request and forward it to Dapi, then return the result.

<?php

// Assuming that Dapi library is already autoloaded. If not, manually include/require it here. 

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

// Initialize DapiClient with your appSecret here
$dapiClient = new Dapi\DapiClient('APP_SECRET');

$headers = getallheaders();
$body = json_decode(file_get_contents("php://input"), true);

// Make dapiClient automatically handle your SDK requests
if (!empty($body)) {
  echo json_encode($dapiClient->handleSDKRequests($body, $headers)); 
} else {
  http_response_code(400);
  echo "Bad Request: No data sent or wrong request";
}