PHP code example of swikly / swikly-php

1. Go to this page and download the library: Download swikly/swikly-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swikly / swikly-php example snippets







// Require the Composer autoloader.
//Instantiate a Swikly API client
$swkAPI = new SwiklyAPI('Your_Api_Key', 'YOUR_API_SECRET', 'development');



// Create a swik object
$swik = new Swik();

// Set all the swik informations
$swik->setClientFirstName("Jean")
    ->setClientLastName("Dupont")
    ->setClientEmail("[email protected]")
    ->setClientPhoneNumber("+33 6 20 20 20 20") // Send SMS to that number
    ->setClientLanguage("FR") // "EN" or "FR"
    ->setSwikAmount("50")
    ->setSwikDescription("1h de canyoning le 12/08/2017....")
    ->setSwikEndDay("12")
    ->setSwikEndMonth("08")
    ->setSwikEndYear("2017")
    ->setSwikId("YOUR_ID")
    ->setSendEmail("true")
    ->setSwikType("security deposit") // "reservation" or "security deposit"
    ->setCallbackUrl('https://mywebsite.com/resultSwik');

// Create and send your new swik to your client
$result = $swkAPI->newSwik($swik);

// Print result of the operation
if ($result['status'] == 'ok') {
	echo "New swik created\n";
    echo "Your client can accept the swik at this address: " . $result['acceptUrl'];
} else {
	echo "Failed to create the swik";
	echo "Error = " . $result['message'];
}


// Create a swik object
$swik = new \Swikly\Swik();

// Set all the swik informations
$swik->setClientFirstName("Jean")
    ->setClientLastName("Dupont")
    ->setClientEmail("[email protected]")
    ->setClientPhoneNumber("+33 6 20 20 20 20") // Send SMS to that number
    ->setClientLanguage("FR") // "EN", "FR", 'NL', 'DE'
    ->setSwikAmount("50")
    ->setSwikDescription("1h de canyoning le 12/08/2017....")
    ->setSwikId("YOUR_ID")
    ->setSendEmail("true")
    ->setCallbackUrl('https://mywebsite.com/resultSwik');

// Create and send your new swik to your client
$result = $swkAPI->newPayment($swik);

// Print result of the operation
if ($result['status'] == 'ok') {
    echo "New payment created\n";
    echo "Your client can pay you at this address: " . $result['acceptUrl'];
} else {
    echo "Failed to create a newPayment";
    echo "Error = " . $result['message'];
}



// Create a swik object
$swik = new Swik();

// Set the Swik Id (yours or the one from Swikly)
$swik->setSwikId("YOUR_ID");

// Deleting the swik
$result = $swkAPI->deleteSwik($swik);

// Print result of the operation
if ($result['status'] == 'ok') {
    echo "Swik deleted correctly";
} else {
    echo "Failed to delete the swik";
    echo "Error = " . $result['message'];
}



// Create a swik object
$swik = new Swik();

// Set the Id you used to create it
$swik->setSwikId("YOUR_ID");

// Get the list of your swiks
$result = $swkAPI->getSwik($swik);

// Print result of the operation
if ($result['status'] == 'ok') {
    echo "My swik = ";
    print_r($result['swik']);
} else {
    echo "Failed to get the swik";
    echo "Error = " . $result['message'];
}



// Get the list of your swiks
$result = $swkAPI->getListSwik();

// Print result of the operation
if ($result['status'] == 'ok') {
    echo "List of swik(s) = ";
    print_r($result['list']);
} else {
    echo "Failed to get the swik list";
    echo "Error = " . $result['message'];
}
bash
composer