Development Kit: PHP

With our PHP development kit, integrate your Cherry Checkout module in only few steps:


Download

To start, download the last SDK version of your format choice:

cherrycheckout-sdk-php.zip
(Version: 1.0.1)
cherrycheckout-sdk-php.tar.gz
(Version: 1.0.1)

The archive contain a folder cherrycheckout. Uncompress it somewhere into your project.

For the following, you will needs of your API keys. You will find it into your dashboard, two kind of keys (a first one for the test mode and a second one for the production mode). We recommend to try first with the test keys (pk_test_xxxxxx et sk_test_yyyyyy).


First call

Create a folder first.php, and add the following lines:

<?php

// Include the SDK loader
require_once('path/to/cherrycheckout/lib/cherrycheckout.php');

use CherryCheckout\Api;
use CherryCheckout\Customer;
use CherryCheckout\Me;
use CherryCheckout\Order;

use CherryCheckout\Exceptions\CustomerEmailMissingException;
use CherryCheckout\Exceptions\CustomerNotSetException;
use CherryCheckout\Exceptions\NoCharityAvailableException;
use CherryCheckout\Exceptions\OrderNotFoundException;
use CherryCheckout\Exceptions\TrackIdAlreadyExistsException;
use CherryCheckout\Exceptions\TrackIdMissingException;

$apiEndPoint = "https://api.cherrycheckout.com/v2";

// Set your keys
$publicKey = "YOUR_PUBLIC_KEY_HERE";
$secretKey = "YOUR_SECRET_KEY_HERE";

// Create your API instance
$api = new Api($apiEndPoint, $publicKey, $secretKey);

try {
    // Make the first call to see if our configuration is good
    $me = $api->getMe();
    echo "Configuration is ok !";
}
catch (\Exception $ex) {
    echo "There was an error making first API call: " . $ex->getMessage();
}
			

Execute this script and verify that the configuration is good. If everything is ok, you can go the next step.


Make an order

After your API instance has been set-up and works, you need to create a order instance.

// First, create a customer object
$customer = new Customer();
$customer
    ->setFirstname('Michael')
    ->setLastname('Jackson')
    ->setEmail('kingofpop@mjcompany.com')
    ->setBirthday('1958-08-29')
    ->setGender('m')
    ->setAddress('55 rue de la république')
    ->setZipCode('75000')
    ->setCity('Paris')
    ->setCountry('France');

// Then, create an order object
$order = new Order();
$order
    ->setOrderPrice(85.90)
    ->setCherryPrice(2)
    ->setTrackId('ODR-5736')
    ->setCurrency('eur')
    ->setCustomer($customer)
    ->setStatus('validated');

			
CherryCheckout\Customer
Firstname* string Customer firstname.
Lastname* string Customer name.
Email* string Customer e-mail address.
Birthday string Customer birthdate. Desired format: 'YYYY-MM-DD'
Gender string Customer gender.
Desired value: 'm', 'f'
Address string Customer address, with number, and street name.
ZipCode string Customer ZIP code
City string Customer city
Country string Customer country
CherryCheckout\Order
OrderPrice* float The order total price, without the Cherry Checkout participation value.
CherryPrice* integer The Cherry Checkout price that you invoiced to the customer. A warning is sending if the amount is different that the one expected.
TrackId* string The order ID, must be unique for each new order.
Currency* string The order currency.
Accepted values: 'chf', 'eur'
Customer* Customer A customer ID
Status* string The order statut.
Accepted values: 'validated', 'canceled'

Now that your order instance is ready, you can send it to the API.
Make this operation only if your customer has added the Cherry Checkout option. It’s not recommended to send order which is not in relation with Cherry Checkout.

// Finally, try to send the order to API
try {
    $api->createOrder($order);
    echo "Ok, order successfully created!";
}
catch(TrackIdAlreadyExistsException $ex) {
	echo "Error, this track id already exists.";
}
catch(NoCharityAvailableException $ex) {
	echo "Error, no charity available.";
}
catch(CustomerNotSetException $ex) {
	echo "Error, customer was missing.";
}
catch(CustomerEmailMissingException $ex) {
    echo "Error, customer e-mail was missing.";
}
catch(\Exception $ex) {
    echo "Unknown error: " . $ex->getMessage();
}

			
CherryCheckout\Exceptions
TrackIdAlreadyExistsException 3001 This exception appear if you try to make a new order with a already used track ID. If you want to modify an order, us in stead the method updateOrder()
NoCharityAvailableException 3004 This exception appear when no charity is linked to your e-commerce website. In this case, contact us.
CustomerNotSetException 3006 This exception appear when you forget to forward the customer data.
CustomerEmailMissingException 3010 This exception appear if you forget to forward the customer e-mail address.

If you don’t have any mistake at this step, you can check if the order has been made successfully. To do so, go to your dashboard and see your orders. (Think to be into the 'prod' mode or 'test' depending of the kind of keys you’re using)

Aperçu de la commande créée dans le Dashboard

Modify an order

You can modify an order, for example if the total amount has changed or if the order has been canceled. In this case, make a new order instance with the same track ID that you used to make it, with the field you want to change.

// Create a new order object, to update it
$order = new Order();
$order
    ->setTrackId('ODR-5736')
    ->setStatus('canceled')
    ->setOrderPrice(95.90);

// Try to update the order to API
try {
    $api->updateOrder($order);
    echo "Ok, order successfully updated!";
}
catch(TrackIdMissingException $ex) {
     echo "Error, the track id was not set.";
}
catch(OrderNotFoundException $ex) {
    echo "Error, order was not found with that track id.";
}
catch(\Exception $ex) {
    echo "Unknown error: " . $ex->getMessage();
}

			
CherryCheckout\Exceptions
TrackIdMissingException 3100 This exception appear if you have made an object order instance without track ID.
OrderNotFoundException 3101 This exception appear if the track ID you gave, doesn’t exist for Cherry Checkout. In this case, you first must make an order with the method createorder()

If you don’t have any mistak, check in your dashboard, that your order has been modified.


Afficher Cherry Checkout aux clients

Et visuellement alors, comment êtes-vous censé représenter ça à vos clients ? A vrai dire, vous êtes libres de faire ce que vous voulez. Nous recommandons cependant quelques points :

  • Afficher le module sur votre page checkout, une fois que le client a terminé de composer son panier, et juste avant de valider sa commande.
  • Afficher les modalités du jeu. Précisez à quelle association va aller le don, quelles sont les chances au client de gagner, ainsi que le montant du gain potentiel.
  • Affichez clairement le prix de la participation
  • Ajoutez un bouton de participation. Lorsque le client clique sur ce bouton, vous devez enregister cette information dans votre commande.
  • Lorsque le client décide de participer, masquez le module, ou remplacez le par un message de confirmation. Ajoutez une ligne dans le panier, pour indiquer la participation Cherry Checkout.
  • Laissez la possibilité au client d'annuler sa participation. Dans ce cas, ré-affichez le plugin dans son état initial.

Si vous ne l'avez pas encore vu, testez notre démonstration de plugin en ligne.


Do you need help ?

You have a problem with our SDK - PHP integration ? Contact our technical team.