dspacelabs / shopify-client
此包已被弃用且不再维护。未建议替代包。
Shopify 客户端
dev-master / 1.0.x-dev
2017-07-11 00:01 UTC
Requires
- dspacelabs/http-client: ^0.1
- guzzlehttp/guzzle: ^6.0
- psr/log: ^1.0
Requires (Dev)
- mockery/mockery: ^0.9.9
- phing/phing: ^2.16
- phpunit/phpunit: ^6.2
This package is not auto-updated.
Last update: 2020-06-02 23:01:34 UTC
README
PHP Shopify 客户端,方便集成到您的项目和应用程序中
要求
- PHP cURL 扩展
- PHP >= 5.4
- 查看 Travis CI 以获取每个版本的构建
- Shopify 合作伙伴账户
安装
composer require "dspacelabs/shopify:^1.0@dev"
使用
将用户重定向到 Shopify 以授权您的应用程序
<?php use Dspacelabs\Component\Shopify\Client; $client = new Client($accessKey, $secretKey); $client->setShop('example.myshopify.com'); // This is the same thing as doing the entire domain //$client->setShop('example'); // List of scopes can be in the Client class $client->setScopes( array( Client::SCOPE_WRITE_CUSTOMERS, Client::SCOPE_READ_CUSTOMERS ) ); $nonce = time(); // Save in session, used in callback action $authorizationUri = $client->getAuthorizationUrl('https://example.com/shopify/callback', $nonce); // redirect user to $authorizationUri
Shopify 将用户重定向回您的回调 URL
<?php use Dspacelabs\Component\Shopify\Client; if (!$session->has('nonce')) { throw new AccessedDeniedError(); } $client = new Client($accessKey, $secretKey); $client->setShop('example.myshopify.com'); // `isValid` takes array of query parameters, think $_GET, $_POST, etc. // This example is using a Request object from the symfony/http-foundation // library if (!$client->isValid($request->query->all())) { throw new \AccessDeniedError(); } // Persist access token in database $accessToken = $client->getAccessToken($request->query->get('code'));
向 Shopify 发送请求
<?php use Dspacelabs\Component\Shopify\Client; $client = new Client($accessKey, $secretKey): $client ->setShop('example.myshopify.com') ->setAccessToken($accessToken); $result = $client->call('GET', '/admin/customers.json'); // Process $result
定期应用程序费用
@todo
创建和使用 webhook
@todo
私有应用程序
请参阅 生成私有应用程序凭据。
<?php use Dspacelabs\Component\Shopify\Client; /** * The API Key and Password are generated for you on Shopify once you create * Your private app. Those are the credentials you need here. */ $client = new Client($apiKey, $password): $client ->setPrivate(true) ->setShop('example.myshopify.com');