XERO Auth2 集成

1.1.0 2021-11-12 13:02 UTC

This package is auto-updated.

Last update: 2024-09-19 11:56:25 UTC


README

#Xero OAuth2.0 API 集成

这个包仅创建用于个人项目,所以所有实现的功能都根据我们个人项目来。请在使用前检查此信息。

// To use this package you have to extend it, create your own PHP class and extend this.
class YourClassName extends \GrimReapper\Xero\Xero{
    // then override it constructor
    public function __construct(array $params)
    {
        if(!empty($params)) {
            parent::__construct($params['client_id'], $params['client_secret'], $params['redirect_uri']);
        }
    }
   // that's it
}

首先创建你的类对象

    $object = new YourClassName();

获取授权 URL

    $data = $object->getAuthorizeURL();
    // it will return array containing URL and State Code
    $state = $data['state']; // this is used to verify state after api redirect to prevent xss
    $url = $data['url']; // use this url to redirect to Xero website for Authentication

添加作用域

    $object->setScopes(['scope1','scope2']);

在重定向到您的站点后获取访问令牌

    $code = $_GET['code']; // get code param from url and pass it to function
    $accessToken = $object->getAccessToken($code);

创建联系人

    $contact = $object->createContact(array $contactData);

获取联系人

    $contact = $object->getContact(string $emailAddress);

创建发票

    $invoice = $object->createInvoice(array $invoiceData);

创建付款

    $payment = $object->createPayment($invoiceID, $account_code, $amount, $date);

创建贷项通知单

    $creditNote = $object->createCreditNotes(array $creditNotesData, bool $returnObj = false);

进行贷项通知单付款

    $creditNote = $object->createCreditNotePayment(array $paymentData);