Download the PHP package bnmetrics/laravel-shopify-api without Composer
On this page you can find all versions of the php package bnmetrics/laravel-shopify-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-shopify-api
Laravel Shopify API Wrapper
This Package provides a easy way for you to building Shopify Apps with Laravel 5. The OAuth authentication is extended upon Laravel's Socialite.
This package supports both public and private apps, including billing.
Installation
You can install this package via composer with:
Or add to your Laravel project composer.json file:
To publish the shopify.php configuration file to app/config
run:
Configuration
Set shopify environment variables your .env file:
Register the service provider in your app/config/app.php
:
Also add the Shopify
facade in your aliases
array in app/config/app.php
:
Basic Usage
Now, you are ready to make a shopify app! here is an example of how it might be used in a controller to retrieve information from a shop via GET request to the API endpoint:
Alternatively, if you already have a token to a specific shopify domain. You can retrieve the API response by using the retrieve() method like so:
Next you will need to make two routes:
CRUD requests to the API endpoints
As of version 1.0.3, GET, PUT, POST, DELETE requests are supported for this package. To make requests, simply call the respective methods following the URL structure of of each endpoints, adding suffix such as "All", "Count", "ById".
API endpoints are referred to as "tiers", for example,
-
products endpoints('admin/products.json', 'admin/products/{id}.json') are tier 1;
-
productsImages endpoints('admin/products/{product_id}/images.json', 'admin/products/{product_id}/images/{image_id}.json') are tier 2;
- Currently, only ordersFulfillmentsEvents have tier 3 ('admin/orders/{order_id}/fulfilments/{fulfillment_id}/events.json', 'admin/orders/{order_id}/fulfilments/{fulfillment_id}/events/{event_id}.json');
Below is an example of how to make requests to endpoints:
Config file
More endpoints can also be added to shopify.php
config file $endpoints array following the same pattern.
- First Tier names should be the array key of the first dimension, and the array values are tier 2;
- if the endpoint has a tier 3 endpoint, add a key
'tier 3'
; - if the tier 2 endpoint node does not need a tier 1 ID to be accessed, the endpoint can be indicated in the
'tierTwoWithoutId'
array.
Billing
As of version 1.0.2, billing support has been added to this package. It supports all three of the billing options shopify provides: RecurringCharge, ApplicationCharge and UsageCharge.
If you are to use Billing for your Shopify app, Add the following onto your config/app.php
file:
Register the service provider in your app/config/app.php
:
Also add the ShopifyBilling
facade in your aliases
array in app/config/app.php
:
Billing Usage
As all shopify charges will need to be activated after creation, we will add a route called activate:
For our previous example controller, you can change the getResponse
method like so:
create() method accepts an validated Shopify object or a User Object, and the options for the charge. Refer to the Property section for different options you can pass in:
RecurringBilling, ApplicationCharge, UsageCharge,
Then we would need to add the activate method():
activate method handles all "status", not only 'accepted', but also when user declines the charge;
Usage Charge
For usage charges, as it is based uppon an existing recurring charge, an activated recurring charge instance must be passed before creating a usage charge.
The recurring charge also require to have 'capped_amount' and 'terms'.
We can modify our activate() method in our controller like so:
All versions of laravel-shopify-api with dependencies
illuminate/support Version ~5.4
guzzlehttp/guzzle Version ~6.0
laravel/socialite Version ~3.0