payload/payload-api
最新稳定版本:0.3.7
Composer 安装命令:
composer require payload/payload-api
包简介
Payload PHP Library
关键字:
README 文档
README
A PHP library for integrating Payload.
Installation
Install using composer
composer require payload/payload-api
Install and run manually
Dependencies
sudo apt install php-curl
Require import.php
<?php require_once('payload-php/import.php'); ?>
Get Started
Once you've installed the Payload PHP library to your environment,
we recommend
using the shorthand alias name of pl for Payload\API.
<?php require_once('vendor/autoload.php'); use Payload\API as pl; ?>
API Authentication
To authenticate with the Payload API, you'll need a live or test API key. API keys are accessible from within the Payload dashboard.
use Payload\API as pl; pl::$api_key = 'secret_key_3bW9JMZtPVDOfFNzwRdfE';
Testing the PHP Library
Tests are contained within the Tests/ directory. To run a test file enter the command in terminal
./vendor/bin/phpunit Tests/{__FILENAME__}.php
Test execution options can be viewed using the ./vendor/bin/phpunit command.
Creating an Object
Interfacing with the Payload API is done primarily through Payload Objects. Below is an example of
creating a customer using the Payload\Customer object.
<?php # Create a Customer $customer = Payload\Customer::create(array( 'email'=>'matt.perez@example.com', 'name'=>'Matt Perez' )); ?>
<?php # Create a Payment $payment = Payload\Transaction::create(array( 'amount'=>100.0, 'type'=>'payment', 'payment_method'=>new Payload\PaymentMethod(array( 'card'=>array('card_number'=>'4242 4242 4242 4242'), 'type'=>'card' )) )); ?>
Accessing Object Attributes
Object attributes are accessible through dot notation.
<?php $customer->name; ?>
Updating an Object
Updating an object is a simple call to the update object method.
<?php # Updating a customer's email $customer->update(array( 'email'=>'matt.perez@newwork.com' )) ?>
Selecting Objects
Objects can be selected using any of their attributes.
<?php # Select a customer by email $customers = Payload\Customer::filter_by( pl::attr()->email->eq('matt.perez@example.com') ); ?>
Use the pl::attr() attribute helper
interface to write powerful queries with a little extra syntax sugar.
$payments = Payload\Transaction::filter_by( pl::attr()->amount->gt(100), pl::attr()->amount->lt(200), pl::attr()->description->contains("Test"), pl::attr()->created_at->gt('2019-02-01') )->all()
Documentation
To get further information on Payload's PHP library and API capabilities, visit the unabridged Payload Documentation.
统计信息
- 总下载量: 3.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-10