esokullu/chargify

交互使用Chargify API v1

v1.0 2013-10-27 04:13 UTC

This package is auto-updated.

Last update: 2024-09-07 18:29:54 UTC


README

这个库为你提供了与Chargify支付平台交互的功能。它是根据Chargify API版本1构建的。

支持的资源

  • 产品
  • 客户
  • 订阅
  • 优惠券
  • 组件
  • 交易

路线图

  • 为支持的资源实现PHPUnit测试。
  • 从Chargify API添加更多资源。

安装

最简单的方法是使用Composer,并将其添加到composer.json的要求部分。

{
  "require": {
    "johannez/chargify": "dev-master"
  }
}

它符合PSR-0规范,因此您也可以使用自己的自定义自动加载器。

用法

一般来说,每个资源都有一个控制器和一个资源类。控制器用于向Chargify发送请求,资源类映射响应数据。

您真正需要的是要操作的资源的控制器

<?php
// $type Singular lower-case name of a suported resource
// $domain Unique sub-domain name (https://DOMAIN.chargify.com)
// $api_key API key that you get through your Chargify environment.
$controller = new \Chargify\Controller\Factory::build($type, $domain, $api_key);

例如,获取系统中所有产品的列表

<?php

$pc = new \Chargify\Controller\Factory::build('product', YOUR_DOMAIN, YOUR_API_KEY);
$products = $pc->getAll();

向Chargify发送数据同样简单。

<?php

$data = array(
  'customer' => array(
    'first_name' => 'Joe',
    'last_name' => 'Smith',
    'email' => 'joe4@example.com',
    'organization' => 'Example Corp.',
    'reference' => 'js21',
  )
);

$cc = new \Chargify\Controller\Factory::build('customer', YOUR_DOMAIN, YOUR_API_KEY);
$new_customer = $cc->create($data);