定制 esensdesign/snipcart-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

esensdesign/snipcart-api

Composer 安装命令:

composer require esensdesign/snipcart-api

包简介

[Forked] A Laravel wrapper for the Snipcart API

README 文档

README

This package makes it super easy to work with the Snipcart API in your Laravel application.

Installation

Install the package using Composer.

composer require esensdesign/snipcart-api

Set your Snipcart Live Secret and Test Secret in your .env. You can find them in your Snipcart Dashboard.

SNIPCART_LIVE_SECRET=********************************
SNIPCART_TEST_SECRET=********************************

You may also publish the config of the package.

php artisan vendor:publish --provider="Esensdesign\SnipcartApi\SnipcartApiServiceProvider"

The following config will be published to config/snipcart-api.php.

<?php

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),

];

Usage Example

Import the package at the top of your file. All of the following examples use the Facade.

use Esensdesign\SnipcartApi\Facades\SnipcartApi;

The SnipcartApi interface is made up of four parts. From defining the HTTP method to sending the request off to Snipcart.

// 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();

This gets a Snipcart product by ID.

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

All responses are wrapped in a Laravel Collection to make working with it super easy.

$product->get('stock');

Snipcart API Reference

Products

Snipcart API Reference on Products

// 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 requires additional parameter methods.
SnipcartApi::put()->product('product_id')->send();

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

Orders

Snipcart API Reference on Orders

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

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

// Update an order by token. This requires additional parameter methods.
SnipcartApi::put()->order('order_token')->send();

Notifications

Snipcart API Reference on Notifications

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

// Post a notification to an order. This requires additional parameter methods.
SnipcartApi::post()->notification('order_token')->send();

Refunds

Snipcart API Reference on Refunds

// 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 requires additional parameter methods.
SnipcartApi::post()->refund('order_token')->send();

Parameter Methods

Pass required or optional parameters to your requests using the fluent interface provided by this package. A common use case is to set a limit and offset to your request.

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

Parameter Methods API Reference

Consult the Snipcart API Reference Documentation to check which parameters are available to what endpoint.

// 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)

Tests

Run the tests like this:

vendor/bin/phpunit

esensdesign/snipcart-api 适用场景与选型建议

esensdesign/snipcart-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「shop」 「api」 「wrapper」 「laravel」 「e-commerce」 「snipcart」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 esensdesign/snipcart-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 esensdesign/snipcart-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 esensdesign/snipcart-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-29