codemojo/startkit

PHP应用程序的插件式组件服务

v0.1.940 2017-09-21 07:33 UTC

README

关于

欢迎来到CodeMojo SDK(启动开发工具包)。CodeMojo帮助您快速部署应用程序组件作为可插拔服务,以减少PHP应用程序的开发时间,提高生产力。

使用SDK非常简单直观。SDK包含以下四个主要服务

  1. 认证服务
  2. 钱包服务
  3. 忠诚度服务
  4. 元标签服务

在此下载PHP SDK

在此下载示例应用程序

查看Wiki以获取更多文档信息

查看仪表板使用说明以了解如何使用仪表板

安装与使用

库存/纯PHP

下载SDK并将autoload.php包含到您的源代码中

Composer

只需将以下内容添加到您的composer.json

{
  "require": {
    "codemojo/startkit": "0.1.*"
  }
}

示例

一旦您在CodeMojo仪表板中启用并配置了忠诚度模块,您就可以像以下示例那样简单使用它。有关仪表板的更多文档信息。

require_once '../sdk/autoload.php';

const CLIENT_ID     = 'sample@codemojo.io';
const CLIENT_SECRET = 'PLB6DHP7VcykRDdvloi2X9tEq3FvsIBhtdn7UdeQ';

// Create an instance of Authentication Service
$authService = new AuthenticationService(CLIENT_ID, CLIENT_SECRET, Endpoints::LOCAL, function($type, $message){
    switch($type){
        case Exceptions::AUTHENTICATION_EXCEPTION:
            echo 'Authentication Exception';
            break;
        case Exceptions::BALANCE_EXHAUSTED_EXCEPTION:
            echo 'Low balance';
            break;
        case Exceptions::FIELDS_MISSING_EXCEPTION:
            echo 'Fields missing';
            break;
        case Exceptions::QUOTA_EXCEPTION:
            echo 'Quota Exhausted Exception';
            break;
        case Exceptions::TOKEN_EXCEPTION:
            echo 'Invalid token Exception';
            break;
        default:
            echo 'Error ' . $message;
            break;
    }
});

// Create an instance of Loyalty Service - If you have more than one wallet service,
// you can optionally pass in the wallet instance as the second argument
$loyaltyService = new LoyaltyService($authService);

// Credit points to user - You can have different set of rules based on the platform
// For example, you can promote your android app by saying Get 5% more cashback when you transact through the Android app
$status = $loyaltyService->addLoyaltyPoints("user1@codemojo.io", 1500, "android", "", 7, "Cashback for Order no. 1231");

// Get the balance in the wallet
$balance = $loyaltyService->getBalance("user1@codemojo.io");

// Check how much maximum can be redeemed by the user for the given (current) transaction value
// Again, you can have different set of rules for redemption based on the platform
$maximumRedemption = $loyaltyService->maximumRedemption("user1@codemojo.io",8500);

// Redeem amount
// (user_id, redemption_amount, current_transaction_value, platform)
$loyaltyService->redeem("user1@codemojo.io", 500, 8500, "android");

有关每个服务可用方法和参数的更多详细信息,请参阅各个服务页面。