1. Go to this page and download the library: Download clippings/purchases 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/ */
clippings / purchases example snippets
// Initialize some products and stores.
$store1 = new Store(['name' => 'My First Store']);
$product1 = new Product(['name' => 'My First Product', 'currency' => 'GBP', 'value' => 2000]);
$product2 = new Product(['name' => 'My Second Product', 'currency' => 'EUR', 'value' => 1000]);
$store1->getProducts()
->add($product1)
->add($product2);
$store2 = new Store(['name' => 'My Second Store']);
$product3 = new Product(['name' => 'My Third Product', 'currency' => 'GBP', 'value' => 5000]);
$store2->getProducts()
->add($product3);
Store::saveArray([$store1, $store2]);
// Now we can purchase something
$purchase = new Purchase();
$purchase
->addProduct($product1)
->addProduct($product2)
->addProduct($product3, 2);
// Freeze all the values of the order,
// so that it remains "frozen", even if prices of products change
$purchase->freeze();
// Initialize omnipay getway - here you will have Paypal, Stripe etc.
$gateway = Omnipay::getFactory()->create('Dummy');
$parameters = [
'card' => [
'number' => '4242424242424242',
'expiryMonth' => 7,
'expiryYear' => 2014,
'cvv' => 123,
],
'clientIp' => '192.168.0.1',
];
$response = $purchase->purchase($gateway, $parameters);
echo $response->isSuccessful();
$purchase = new Purchase();
// Adding a product
$purchase->addProduct($product);
// Adding multiple products
$purchase->addProduct($product, 5);
$purchase = new Purchase();
// Adding a purchaseItem
$purchase->addPurchaseItem($store, $purchaseItem);
$purchase = new Purchase();
$product = new Product(['price' => 100]);
$purchase->addProduct($product, 3);
$productItem = $purchase->getItems()->getFirst();
// This will return the value of the product * quantity
// In this case 300
echo $productItem->getValue();
// Perform a freeze:
$purchase->freeze();
$product->price = 4000;
// Will still be 300
echo $productItem->getValue();
$purchase = new Purchase(['currency' => 'GBP']);
$product = new Product(['price' => 100, 'currency' => 'EUR']);
$purchase->addProduct($product, 3);
$productItem = $purchase->getItems()->getFirst();
// This will not 300, but convert it to GBP (around 240)
echo $productItem->getValue();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.