emmelaineglz/orchextra-coupons-generation

优惠券生成服务消费SDK

dev-master 2017-07-07 16:59 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:20:44 UTC


README

优惠券生成服务消费SDK

使用composer安装

composer require emmelaineglz/orchextra-coupons-generation-php

要访问此SDK,需要认证。

composer require emmelaineglz/orchextra-client-php

认证使用示例

require "vendor/autoload.php";
use Gigigo\Orchextra\Auth;
use Gigigo\Orchextra\Generation;

实例化类

$auth = new Auth('https://ejemplo.com.mx');

引用客户端认证方法并调用“getToken()”方法以获取访问令牌。

$client = $auth->authClient('cliente1', '12345');
$token = $auth->getToken();

现在实例化类,并将url、版本和令牌发送给它。

$campaign = new Generation\Campaign('https://ejemplo.com.mx', 'v1', $token);

有了实例,我们可以访问其方法,可以通过setter设置参数,可以使用setter或发送包含所需内容的数组。

$campaign->setWith ( [
    'user',
    'user.clients'
  ]);
$campaign->setFields ( [
    'name',
    'description'
  ]);
$campaign->setFilters ( [
    'name' => 'Campaña 1',
    'description' => 'Campaña de promoción'
  ]);
$campaign->setPagination ( [
  'perPage' => 3,
  'page' => 2
]);
$collection = $campaign->all ([
    'with' => [
      'user',
      'user.clients'
    ],
    'fields' => [
      'name',
      'description',
      'user.email',
      'user.clients.clientSecret'
    ],
    'filters' => [
      'name' => 'Campaña de Prueba Ethel Replace 2',
    ],
    'pagination' => [
        'perPage' => 3
        'page' => 2
        ]
  ]);

可能获得的响应将是一个对象实例的集合,一个简单的实例或一个数组。

以下是这样访问集合的方式

$collection->first();

转换为数组

$collection->first()->toArray();

应用操作

$collection->first()->replace();
$collection->first()->update();
$collection->first()->delete();

直接访问属性

$collection->first()->name;
$collection->first()->description;