deboorn/ccb-api

教堂社区建设者API助手

v1.0.2 2015-11-20 19:03 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:20:32 UTC


README

CCB-Api

  • PHP 5教堂社区建设者助手
  • 许可证:Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)
  • 请尊重上述许可证(CC BY-NC 3.0),它是严格非商业的。
  • 商业许可证仅需支付15美元的一次性费用。
  • 如果您是受薪自由职业者为教堂开发,则需要商业许可证。
  • 这些文件并非由教堂社区建设者官方支持。
  • 有关此软件的问题请联系 daniel.boorn@gmail.com

如何安装

安装 deboorn/ccb-api

$ composer require deboorn/ccb-api

使用示例

$ccb = new \CCB\Api('username', 'password', 'https://yourdomain.ccbchurch.com/api.php');


# Example 1 -- How to fetch and loop over api data


// fetch transaction detail type list
$response = $ccb->fetch('transaction_detail_type_list');

// loop over results (if any)
if ($response['transaction_detail_types']->attr('count') > 0) {
    foreach ($response['transaction_detail_type'] as $element) {
        $item = pq($element);
        var_dump($item['name']->text());
    }
}


# Example 2 -- How to build and post xml body data to api

// get model from local file /ccb/templates/import_online_gifts.xml
// you could also skip this and build your xml string directly
// add your own templates by saving them from the api docs to the template directory
$model = $ccb->fromTemplate('srv_endpoint_string');
$model['element_name']->text('value');
// ...
$response = $ccb->fetch('srv_endpoint_string', $model, 'POST');
var_dump($response);

# Example 3 -- How to build and send GET data to api

$params = array(
    // required
    'coa_category_id' => 50,
    'individual_id'   => 0,
    'amount'          => number_format(rand(100, 300), 2),
    // optional
    'merchant_transaction_id'     => uniqid('OG'), // max 50
    'merchant_authorization_code' => 'AP', // max 10
    'merchant_notes'              => 'Test Donation Api', // max 100
    'merchant_process_date'       => date('Y-m-d'),
    'first_name'                  => 'John',
    'last_name'                   => 'Doe',
    'street_address'              => '12th Ave North', // max 150
    'city'                        => 'Myrtle Beach', // max 30
    'state'                       => 'SC', // max 3
    'zip'                         => '29579', // max 10
    'email'                       => 'john.doe@example.com',
    'campus_id'                   => 1,
    'payment_method'              => 'API - CCard',
    'payment_method_type'         => 'VISA', // enum (Other, MC, VISA, AMEX, DISC
    'transaction_date'            => date('Y-m-d'),
);

try {
    $response = $ccb->fetch('online_giving_insert_gift', $params);
    var_dump($response['gift_id']->text());
} catch (\CCB\Exception $e) {
    var_dump($e->getMessage(), $e->getCode(), $e->getXml());
}