roketin/connect

Roketin 引擎 API 客户端

v0.0.9 2018-05-03 08:06 UTC

This package is auto-updated.

Last update: 2024-09-15 21:36:41 UTC


README

Latest Version License Total Downloads

RClient 是 Roketin API 的标准客户端应用程序,用于加速连接并将 Roketin 引擎 API 的基本功能集成到客户端网站。

API 文档

Roketin API 的文档可以在文档中找到。

安装

Laravel 5

"require": {
    "laravel/framework": "5.0.*",
    "roketin/connect": "v0.0.9"
}

接下来,从终端运行 Composer 更新命令

composer update

or

composer update "roketin/connect"

配置

  1. 打开 config/app.php 并将此行添加到您的 Service Providers 数组中
  Roketin\Providers\RoketinServiceProvider::class,
  1. 打开 config/app.php 并将此行添加到您的 Aliases 中
    'Roketin' => Roketin\Facades\RoketinFacade::class
  1. 使用以下命令发布配置

    $ php artisan vendor:publish --provider="Roketin\Providers\RoketinServiceProvider"

  2. 根据 .env.example 文件创建 .env 文件,并根据客户端凭证更改值

  ROKETIN_API=http://dev.roketin.com/api/v2.2/
  ROKETIN_PUBLIC=http://dev.roketin.com/

  ROKETIN_TOKEN=aBCd1234
  ROKETIN_USERNAME=roketin
  ROKETIN_RX=4241639264053293060625251241576152575759

如何使用

基本

您可以使用以下方式调用 Roketin 对象:Roketin::model()->get()

    use Roketin;
    
    $menus = Roketin::menus()->get();
    $posts = Roketin::posts()->get();
    $products = Roketin::products()->get();
    $variants = Roketin::variants()->get();
    etc..

通过 id/slug 等获取单个对象

    /*
     * Same as fetching object, but in singular form (without 's')
     * the second argument can be id or slug or etc ..
     * this is dynamic function call to Roketin Engine API
     */
    
    $home = Roketin::menu('home')->get();
    $post = Roketin::post('latest-update')->get();

条件

通过简单的 where 条件获取对象

    /**
     * @param $field
     * @param $operation
     * @param $value
     */

    $posts = Roketin::posts()->where('title','like','vacation')->get();
    
    //NOTE : 
    //It doesn't need to add % if using 'like' operator

通过简单的 orWhere 条件获取对象

    /**
     * @param $field
     * @param $operation
     * @param $value
     */

    $posts = Roketin::posts()
                        ->where('title','like','vacation')
                        ->orWhere('title','like','holiday')
                        ->get();
    
    //NOTE : 
    //It doesn't need to add % if using 'like' operator

高级 where 或 orWhere 分组条件

    /**
     * @param $field
     * @param $operation
     * @param $value
     */

    $posts = Roketin::posts()
                        ->where('title','like','vacation')
                        ->orWhere('title','like','holiday')
                        ->where('date','>=','2016-04-10')
                        ->where('date','<=','2016-04-18')
                        ->get();
    
    //NOTE : 
    //It will result query grouping 
    // (title like vacation or title like holiday) 
    // AND 
    // (date >= 2016-04-10 and date <= 2016-04-18 )

排序

通过字段排序获取 Roketin 对象 API

    /*
     * sorting object before fetch
     * 
     * @param $field
     * @param $direction (optional) default is ASC
     * /

    $posts = Roketin::posts()->sortBy('created_at')->get();
    $posts = Roketin::posts()->sortBy('created_at','DESC')->get();

分组

通过字段分组获取 Roketin 对象 API

    /*
     * grouping object before fetch
     * 
     * @param $field
     * /

    $posts = Roketin::posts()->groupBy('created_at')->get();
    $posts = Roketin::posts()->groupBy('id')->groupBy('created_at')->get();

分页

分页获取对象

    /*
     * paginate object before fetch
     * 
     * @param $size default value is 10
     * @param $page (optional)
     * /

    $posts = Roketin::posts()->paginate(10)->get();
    $posts = Roketin::posts()->paginate(10,2)->get();

标签

获取所有标签帖子

    $tags = Roketin::tags()->get()

通过标签获取所有帖子

    /*
     * @param $tag separated by ';'
     * @param $is_blog (optional) default value is false
     */
    $posts = Roketin::tags('tag_1;tag_2',false)->get()

存档

按年份获取存档

    /*
     * @param $tags (optional) default value is '', multiple (; as separator)
     * @param $year (optional) default value is '2016'
     */
    $archive = Roketin::archives('tags;tags2;another tag','2016')->get()

运输

获取所有可用的国家

    $countries = Roketin::shipping()->countries()

获取所有可用的省份(目前仅在印度尼西亚可用)

    $province = Roketin::shipping()->province()

获取所有可用的城市(目前仅在印度尼西亚可用)

    /*
     * @param $provinceid
     */

    $cities = Roketin::shipping()->province(9)->cities()

计算运输费用

    /*
     * @param $destination = city id
     * @param $courier = JNE/TIKI/POS
     * @param $weight = item weight in KG (optional) default value 1
     * @param $origin = city id
     */

    $costs = Roketin::shipping()->costs(23, 'JNE')

订单

创建销售订单

    /*
     * @param array $generalData
     * @param array $customerData
     * @param array $products
     * @param $bcc(optional), default = null
     */
     
     $generalData = [
            "notes"         => "some string here",
            "is_email_only" => true, //default value false (for customer guest)
            "ship_cost"     => 10000,
            'ship_provider' => "JNE"
     ];

     $customerData = [
            "first_name" => "Roketin",
            "last_name"  => "User",
            "phone"      => "+628123456789",
            "email"      => "user@roketin.com",
     ];

     $products = [
         [
             "id"         => "2623",
             "qty"        => "1",
             "sku"        => "ADVHEL001",
             "price_type" => "retail_price",
         ],
     ];                                 
    $order = Roketin::order()->create($generalData, $customerData, $products, 'test@mailinator.com')

注意

  • 有关详细属性,请参阅销售订单 API 文档此处

确认支付订单

    /*
     * @param $invoice_number
     * @param $payment_type
     * @param $total
     * @param $customer_name
     * @param $customer_bank
     * @param $transaction_number
     * @param Image $image
     * @param $bank_account(optional), default = null
     * @param $paid_date(optional), default = null
     * @param $bcc(optional), default = null
     */
     
    //you can create image for bank transfer that 
    //showing transfer is success
    //by using Image::make()
    $img = Image::make(Input::file('image'))
    
    $payment = Roketin::order()
                ->confirm('SI16041300058', 
                          'TRANSFER', 
                          '150000', 
                          'Customer Roketin', 
                          'Bank BCA', 
                          'TRX-123', 
                          $img, 
                          '0853909090',
                          '2016-04-10',
                          'bcc@mailinator.com')

取消销售订单及其发票

    /*
     * @param $invoice_number
     */

    $order = Roketin::order()->void('ASD02262016')

订阅

提交订阅电子邮件

    /*
     * @param $email
     * @param $bcc(optional), default = null
     */

    $subscribe = Roketin::subscribe('somebody@anythin.com', 'bcc@mailinator.com')

消息

向 Roketin 引擎收件箱发送消息

    /*
     * @param $sender_name
     * @param $sender_email
     * @param $sender_phone
     * @param $message_title
     * @param $message_body
     * @param $bcc(optional), default = null
     */

    $msg = Roketin::message()
                    ->send(
                    'test',
                    'test@mailinator.com',
                    '123123',
                    'test mesage',
                    'hai',
                    'bcc@mailinator.com')

消息

向 Roketin 引擎收件箱发送消息

    /*
     * @param $sender_name
     * @param $sender_email
     * @param $sender_phone
     * @param $message_title
     * @param $message_body
     * @param $bcc(optional), default = null
     */

    $msg = Roketin::message()
                    ->send(
                    'test',
                    'test@mailinator.com',
                    '123123',
                    'test mesage',
                    'hai',
                    'bcc@mailinator.com')

优惠券

检查优惠券的有效性

    /*
     * @param $code
     * @param $voucher_type (optional), default = null
     * voucher type can be giftvoucher (voucher in 
     * exchange to money nominal) or
     * other (voucher to exchange to free product)
     * default is voucher_type is other
     */

    $check = Roketin::voucher()->check('AS123D')

使优惠券无效(使用优惠券)

    /*
     * @param $voucher_code
     * @param $voucher_type (optional) default is other
     * @param $used_by (optional) default is logged in user
     */

    $check = Roketin::voucher()->invalidate('AS123D')

用户

注册新用户

    /*
     * @param $first_name
     * @param $last_name
     * @param $email
     * @param $phone
     * @param $password
     * @param $password_confirmation
     * @param $bcc(optional), default = null
     * @return user object
     */

    $user = Roketin::user()->register('first_name', 'last_name', 'email', 'phone', 'password', 'password_confirmation', 'bcc');

用户激活

    /*
     * @param $token
     * @return true if success activation
     * @return error object if present
     */

    $activation = Roketin::user()->activate('token');

将激活码重新发送到电子邮件

    /*
     * @param $email
     * @return true if success activation
     * @return error object if present
     */

    $resend = Roketin::user()->resendActivation('someone@somthing.com');

忘记密码(生成并发送到用户电子邮件的令牌)

    /*
     * @param $email
     * @param $bcc(optional), default = null
     * @return true if success activation
     * @return error object if present
     */

    Roketin::user()->forgot('someone@somthing.com', 'bcc@mailinator.com');

重置密码

    /*
     * @param $token
     * @param $password
     * @param $password_confirmation
     * @param $bcc(optional), default = null
     * @return true if success activation
     * @return error object if present
     */

    Roketin::user()->resetPassword('token','asdf','asdf', 'bcc@mailinator.com');

登录

    /*
     * @param $email
     * @param $password
     * @param $type (optional) default = user, available = vendor
     * @return true if success activation
     * @return error object if present
     */

    Roketin::auth()->login('somebody@somthing.com','asdf');

当前用户

    /*
     * @return user object
     */

    Roketin::auth()->user();

更新用户数据

    /*
     * @return user object
     */

    Roketin::user()->update(['first_name' => 'John']);

注意

  • 有关详细属性,请参阅销售订单 API 文档此处

获取交易历史数据

    /*
     * @return user object
     */

    Roketin::user()->transactionHistory()->get();

注意

  • 您也可以使用 where()、orWhere() 等查询此方法

登出

    /*
     * @return boolean
     */

    Roketin::auth()->logout();

其他

按类别获取产品变体

    /*
     * @param $category_name
     * @return variants object
     */

    Roketin::variantsByCategory($category_name)->get();