承接 chemistrymarketing/zoho-subscriptions-sdk 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chemistrymarketing/zoho-subscriptions-sdk

Composer 安装命令:

composer require chemistrymarketing/zoho-subscriptions-sdk

包简介

Zoho Subscriptions SDK

README 文档

README

Partial PHP SDK for Zoho Subscriptions

Usage

To instantiate a client, use the static build method with your organisation ID and Auth token from Zoho.

use ZohoSubscription\Client as ZohoClient;

$client = new ZohoClient::build($id, $token);

Customers

If you're creating a customer, most of the customer data is not technically required (except the email address), so we have setter methods to add it when it is provided:

$customer = new \ZohoSubscription\Resources\Customers\Customer($email);
$customer->setName($firstName, $lastName, $salutation);
$customer->setCompanyName($companyName);
$customer->setCurrencyCode($currencyCode);
$customer->setDisplayName($displayName);
$customer->setVatRegistration($countryCode, $vatNumber);

You can add custom fields to customers like so:

$customer->addCustomField('label', 'value', 'data type');
$customer->addCustomField('label 2', 'value', 'data type');

Then when you're ready to save the customer, you send it to the method in the client, which returns the customer ID:

$id = $client->send($client)->getId();

Customer Addresses

adding an address to a customer requires you to create Address objects:

$address = new  new \ZohoSubscription\Resources\Customers\Address();
$address->setRegion($country, $state, $zip);
$address->setLocale($street, $city, $attention);

then you can add it to the billing address or the shipping address on the customer before sending the request:

$customer->setBillingAddress($address);

$customer->setShippingAddress($address);

Hosted Page: Subscriptions

Creating a subscription is, at it's simplest, a case of creating a Subscription entity and sending it to the client:

$subscription = new  new \ZohoSubscription\Resources\HostedPages\Subscription($customerId, $planId);

$url = $client->send($subscription)->getId();

This creates a hosted page, and returns the URL which your user needs to be redirected to in order to complete their subscription.

You can optionally add a redirect url to the subscription before you send the request to let Zoho know where to send the user after the order has been completed:

$subscription->addRedirectUrl($redirectUrl);

Regions

Zoho Subscriptions are available in different regions, which have different URL's to access the API.

To change to the EU region, you can use the setApiRegionEU() method on the Client class, and change it back with the setApiRegionCOM()

$client = ZohoSubscription\Client::build();

$client->setApiRegionEU();
$client->setApiRegionCOM();

$request = new ZohoSubscription\Resources\Customers\Customer('test@example.com');

$client->send($request);

Creating new API methods

I have currently only created API classes for the functionality that is needed for the current project I am working on. If you need anything else, you can easily do so by implementing the ZohoSubscription\Contracts\Requestable interface and optionally using the ZohoSubscription\Partials\HasRequestables trait, for example this is a very basic Payment API implementation:

namespace MyCo\Zoho\Resources\Payments;

use ZohoSubscription\Contracts\Requestable;
use ZohoSubscription\Partials\HasRequestables;

class Payment implements Requestable
{
    use HasRequestables;
    
    public function __construct(string $customerId, int $amount, string $paymentMode)
    {
        $this->attributes['customer_id'] = $customerId;
        $this->attributes['amount'] = $amount;
        $this->attributes['payment_mode'] = $paymentMode;
    }

    /**
     * @return string
     * @throws \Exception
     */
    public function getUri(): string
    {
        return 'payments';
    }

    /**
     * @return string
     * @throws \Exception
     */
    public function getId(): string
    {
        if (is_null($this->response)) {
            throw new \Exception('Trying to get ID when request not sent yet');
        }
        return json_decode($this->response->getBody())->payment->payment_id;
    }
}

which you could build up and pass to the client's send method.

$payment = new MyCo\Zoho\Resources\Payments($customerId, $amount, 'cash');

$paymentId = $client->send($payment)->getId();

统计信息

  • 总下载量: 421
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-09-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固