Wiki
Clone wikiphpsdkswikly / Create a swik
#Create a swik
Before reading this make sure you understood the Initialization process. It will be required for Step 3.
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: you need to use a string. By default the value is "true". Possible values: "true", "false". All other values are converted to "false" automatically. If set to true Swikly sends an email to the client to warn him about the new Swik. If set to false nothing is sent and you need to warn the client yourself.
All the others parameters are REQUIRED.
<?php $swik->setClientFirstName("Jean") ->setClientLastName("Dupont") ->setClientPhoneNumber("+33 6 20 20 20 20") ->setClientEmail("jean.dupont@gmail.com") ->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" used only when setSendEmail("true") ->setCallbackUrl('https://mywebsite.com/resultSwik');
3 - Sending the new swik
The newSwik function makes a call on the Swikly API. If all the information provided is correct the swik is created.
<?php $result = $swkAPI->newSwik($swik);
4 - Handling the result
On success
The Swik is correctly created, you get the URL for your client to accept it and the Swikly ID of your Swik:
<?php if ($result['status'] == 'ok') { echo "New swik created"; echo "Your client can accept the swik at that address: " . $result['acceptUrl']; echo "The Swikly Id is: " . $result['swiklyId']; } else { echo "Failed create swik"; echo "Error = " . $result['message']; }
When the Swik is accepted and validated by Swikly we are using the callback URL. We are doing a POST request on the callback URL 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
On Error
A message that you can display or log if needed is returned:
<?php if ($result['status'] == 'ko') { echo "Failed create swik"; echo "Error = " . $result['message']; }
5 - Full code
<?php // 1. Load the SDK file. require 'YOUR/PATH/phpSdkSwikly.php'; $swkAPI = new \Swikly\SwiklyAPI('example_api_key', 'API_SECRET', 'development'); // Create a swik object $swik = new \Swikly\Swik(); // Set all the swik informations $swik->setClientFirstName("Jean") ->setClientLastName("Dupont") ->setClientEmail("jean.dupont@gmail.com") ->setClientPhoneNumber("+33 6 20 20 20 20") ->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" used only when setSendEmail("true") ->setCallbackUrl('https://mywebsite.com/resultSwik'); // Send your new swik to your client $result = $swkAPI->newSwik($swik); // Print result of the operation if ($result['status'] == 'ok') { echo "New swik created"; echo "Your client can accept the swik at that address: " . $result['acceptUrl']; } else { echo "Failed create swik"; echo "Error = " . $result['message']; }
Updated