PHP code example of aerni / snipcart-api

1. Go to this page and download the library: Download aerni/snipcart-api 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/ */

    

aerni / snipcart-api example snippets




return [

    /*
    |--------------------------------------------------------------------------
    | Snipcart API Keys
    |--------------------------------------------------------------------------
    |
    | Your secret Snipcart API Keys for the Live and Test Environment.
    |
    */

    'live_secret' => env('SNIPCART_LIVE_SECRET'),
    'test_secret' => env('SNIPCART_TEST_SECRET'),

    /*
    |--------------------------------------------------------------------------
    | Test Mode
    |--------------------------------------------------------------------------
    |
    | Set this to 'false' to authenticate using the 'live_secret'.
    | You probably want to do this in production only.
    |
    */

    'test_mode' => env('SNIPCART_TEST_MODE', true),

];

use Aerni\SnipcartApi\Facades\SnipcartApi;

// 1. Set the HTTP method to be used for the API request.
SnipcartApi::get() ...

// 2. Call the main method for the request.
SnipcartApi::get()->product('product_id') ...

// 3. Add optional parameter methods.
SnipcartApi::get()->product('product_id')->limit(10)->offset(10) ...

// 4. Send the request off to Snipcart.
SnipcartApi::get()->product('product_id')->limit(10)->offset(10)->send();

$product = SnipcartApi::get()->product('product_id')->send();

$product->get('stock');

// Get all products.
SnipcartApi::get()->products()->send();

// Post all products found on the URL.
SnipcartApi::post()->products('fetch_url')->send();

// Get a product by ID.
SnipcartApi::get()->product('product_id')->send();

// Update a product by ID. This 

// Get all orders.
SnipcartApi::get()->orders()->send();

// Get an order by token.
SnipcartApi::get()->order('order_token')->send();

// Update an order by token. This 

// Get all notifications of an order.
SnipcartApi::get()->notifications('order_token')->send();

// Post a notification to an order. This 

// Get all refunds of an order.
SnipcartApi::get()->refunds('order_token')->send();

// Get a specific refund from an order.
SnipcartApi::get()->refund('order_token', 'refund_id')->send();

// Post a refund to an order. This 

SnipcartApi::get()->products()->limit(10)->offset(10)->send();

// The maximum number of items returned by the request.
limit(int $limit);

// The number of items that will be skipped.
offset(int $offset);

// The product ID defined by the user.
userDefinedId(string $id);

// The product ID defined by the user.
productId(string $id);

// Filter products to return those that have been bought from specified date.
from(string $from);

// Filter products to return those that have been bought until specified date.
to(string $to);

// The URL where we will find product details.
fetchUrl(string $url);

// Specifies how inventory should be tracked for this product.
// Can be 'Single' or 'Variant.
// Variant can be used when a product has some dropdown custom fields.
inventoryManagementMethod(string $method);

// Allows to set stock per product variant.
variants(array $variants);

// The number of items in stock.
// Will be used when 'inventoryManagementMethod' is 'Single'.
stock(int $stock = null);

// If true a customer will be able to buy the product even if it's out of stock.
// The stock level might be negative.
// If false it will be impossible to buy the product.
allowOutOfStockPurchases(bool $bool)

// A status criteria for your order collection.
// Possible values: InProgress, Processed, Disputed, Shipped, Delivered, Pending, Cancelled
status(string $status)

// The order payment status.
// Possible values: Paid, Deferred, PaidDeferred, ChargedBack, Refunded, Paidout,
// Failed, Pending, Expired, Cancelled, Open, Authorized.
paymentStatus(string $status)

// The invoice number of the order to retrieve.
invoiceNumber(string $invoiceNumber)

// The name of the person who made the purchase.
placedBy(string $name)

// Returns only the orders that are recurring or not.
isRecurringOrder(bool $bool)

// The tracking number associated to the order.
trackingNumber(string $number)

// The URL where the customer will be able to track its order.
trackingUrl(string $url)

// A simple array that can hold any data associated to this order.
metadata(array $metadata)

// The type of notification.
// Possible values: Comment, OrderStatusChanged, OrderShipped, TrackingNumber, Invoice
type(string $type)

// The delivery method of the notification.
// Possible values: Email, None
deliveryMethod(string $method)

// The message of the notification.
// Possible values: Email, None
message(string $message)

// The amount of the refund.
amount(string $amount)

// The reason for the refund.
comment(string $comment)
bash
php artisan vendor:publish --provider="Aerni\SnipcartApi\SnipcartApiServiceProvider"