PHP code example of chemistrymarketing / zoho-subscriptions-sdk

1. Go to this page and download the library: Download chemistrymarketing/zoho-subscriptions-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chemistrymarketing / zoho-subscriptions-sdk example snippets


use ZohoSubscription\Client as ZohoClient;

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

$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);

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

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

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

$customer->setBillingAddress($address);

$customer->setShippingAddress($address);

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

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

$subscription->addRedirectUrl($redirectUrl);

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

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

$request = new ZohoSubscription\Resources\Customers\Customer('[email protected]');

$client->send($request);
 
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;
    }
}




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

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