Wiki

Clone wiki

phpsdkswikly / Make a Direct Swik

#Make a Direct Swik

A Direct Swik you said ?


- What is a Direct Swik ?

  • It is a new way of integrating Swikly in you own website.

- How does it work ?

  • When you're creating a new Swik, we are sending you back a redirection URL to our website. Once you redirect your client to that address, he has to confirm the form with all his informations and fill his credit card details.

  • If his credit card informations are right we are redirecting him to the callback URL that you gave us and the money is secured by our system.

- How could I be sure that it worked ?

  • Go to Swikly and login into your account. On your dashboard you'll be able to see all your swiks.

Technical informations


Before looking at this make sure you understood the Initialization

It will be required for the Step 3.

All the information are for the server side.

Full examples are availables in the examples/ folder of this repository.

1 - Create a swik object

<?php
$swik = new \Swikly\Swik();

2 - Set all the informations for your swik

Optional parameters:

  • ClientFirstName, ClientLastName, ClientPhoneNumber, SendEmail.

  • SendEmail: If "true" Swikly send an email to the client to warn him about the newly created Swik. If false, the client is not warned about the creation of the swik, he will just receive a confirmation once he will validate the Swik. You need to use a string. By default the value is "true". Possible values: "true", "false". All other values are converted to "false" automatically.

All the others parameters are REQUIRED.

<?php
$swik->setClientFirstName($userData['firstName'])
    ->setClientLastName($userData['lastName'])
    ->setClientEmail($userData['emailUser'])
    ->setClientPhoneNumber($userData['phoneNumber'])
    ->setClientLanguage($userData['language'])
    ->setSwikAmount("35")
    ->setSwikDescription("A short description of the swik")
    ->setSwikEndDay("12")
    ->setSwikEndMonth("04")
    ->setSwikEndYear("2017")
    ->setSwikId($id)
    ->setSendEmail("true")
    ->setSwikType("security deposit") // "reservation" or "security deposit" used only when setSendEmail("true")
    ->setCallbackUrl('http://mywebsite.com/confirmation');

3 - Creating the new swik

The newDirectSwik function make a call on the swikly api. If all the informations are correct the swik is created and you receive the redirect URL.

<?php
$result = $swkAPI->newDirectSwik($swik);

4 - Handling the result

An error happened

The status is set to 'ko' and an error message is set.

<?php
if ($result['status'] == 'ko') {
    error_log("Failed to create a swik " . $result['message']);
}
echo $result;

On success

When the Swik is accepted and validated by Swikly we are using the callback URL. We are doing a GET request with some parameters:

  • status: is set to "ok"
  • id: it is the custom id that you set (or empty if you gave none)
  • swiklyId: it is the Swik Id that Swikly is providing

5 - Full code

<?php
// 1. Load the SDK file.
require 'YOUR/PATH/phpSdkSwikly.php';

$swkAPI = new \Swikly\SwiklyAPI('example_api_key', 'API_SECRET', 'development');

function makeNewDirectSwik($id, $userData) {
    // Create a Swik object
    $swik = new \Swikly\Swik();

    // Set all the Swik informations
    $swik->setClientFirstName($userData['firstName'])
        ->setClientLastName($userData['lastName'])
        ->setClientEmail($userData['emailUser'])
        ->setClientPhoneNumber($userData['phoneNumber'])
        ->setClientLanguage($userData['language'])
        ->setSwikAmount("35")
        ->setSwikDescription("A short description of the swik")
        ->setSwikEndDay("12")
        ->setSwikEndMonth("04")
        ->setSwikEndYear("2017")
        ->setSwikId($id)
        ->setSendEmail("true")
        ->setSwikType("security deposit") // "reservation" or "security deposit" used only when setSendEmail("true")
        ->setCallbackUrl('http://mywebsite.com/confirmation');

    // Create the new Swik and get the redirect URL to validate it
    $result = $swkAPI->newDirectSwik($swik);

    // Log the error if one occured and return the result
    if ($result['status'] == 'ko') {
        error_log("Failed to create a swik " . $result['message']);
    }
    return $result;
}

echo json_encode(makeNewDirectSwik($myId, $_POST));

<< Previous Page || Back to menu || Next Page >>

Updated