1. Go to this page and download the library: Download lunalabs-srl/zuora-api 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/ */
lunalabs-srl / zuora-api example snippets
unaLabs\ZuoraApi\ZuoraApi;
use LunaLabs\ZuoraApi\ZuoraCallout;
use LunaLabs\ZuoraApi\Exceptions\ZuoraApiException;
// Zuora credentials.
$zuoraConfig = [
'clientId' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
'clientSecret' => 'XXXXX=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=XXX',
'baseUri' => 'https://rest.sandbox.eu.zuora.com',
'apiVersion' => 'v1'
];
try {
// Instance.
$zuora = new ZuoraApi($zuoraConfig);
// Retrieves all the stored accounts.
$response = $zuora->account()->all();
// Prints the result as JSON.
header('Content-Type: application/json');
echo json_encode($response);
} catch (ZuoraApiException $e) {
// In case of error, you can handle the formatted object response through some useful properties.
header('Content-Type: application/json');
echo json_encode($e->errorFormatter());
}
// If you want to associate a tokenized credit card to an existing Zuora account, you have to use a payload like this:
$tokenizedCard = [
'AccountId' => 'ZUORA_ACCOUNT_ID',
'Type' => 'CreditCardReferenceTransaction',
'UseDefaultRetryRule' => true,
'TokenId' => 'CARD_ID_FROM_YOUR_PAYMENT_GATEWAY',
'SecondTokenId' => 'REFERENCE_ID_FROM_YOUR_PAYMENT_GATEWAY'
];
$tokenizedSepa = [
'AccountId' => 'ZUORA_ACCOUNT_ID',
'Type' => 'BankTransfer',
'BankTransferType' => 'SEPA',
'UseDefaultRetryRule' => true,
'BankTransferAccountNumber' => 'IT4000000000000000000000000', // The user's IBAN
'MandateReceived' => 'Yes',
'ExistingMandate' => 'Yes',
'MandateID' => 'SLMP000000000'
];
try {
// Retrieves the payment method details by its ID.
$response = $zuora->paymentMethod()->get('PAYMENT_METHOD_ID');
// Creates the given payment method (credit card or SEPA).
// This response will return the payment ID to use to set the default payment.
$response = $zuora->paymentMethod()->create($tokenizedCard);
// Updates the desired payment method by its ID with the new data.
$response = $zuora->paymentMethod()->update('PAYMENT_METHOD_ID', $newData);
// Deletes the given payment method ID (you can not delete the default payment method).
$response = $zuora->paymentMethod()->delete('PAYMENT_METHOD_ID_TO_DELETE');
// Associates the given payment method to the given existing account ID, marking it as default payment method.
$response = $zuora->paymentMethod()->setDefaultPayment('ZUORA_ACCOUNT_ID', 'PAYMENT_METHOD_ID');
} catch (ZuoraApiException $e) {
// ...
}
try {
// Retrieves the product details by its ID.
$response = $zuora->product()->get('PRODUCT_ID');
// Retrieves all the rate plans of the given product ID (to be used during the order creation).
$response = $zuora->product()->getRatePlans('PRODUCT_ID');
} catch (ZuoraApiException $e) {
// ...
}
$orderData = [
'description' => 'Test order description',
'existingAccountNumber' => 'ZUORA_ACCOUNT_ID',
'orderDate' => '2020-01-01',
'subscriptions' => [
...
]
];
try {
// Retrieves the order details by the order number.
$response = $zuora->order()->get('ORDER_NUMBER');
// Creates the order and the subscription for the desired account.
$response = $zuora->order()->create($orderData);
// Deletes the given order by the order number.
$response = $zuora->order()->delete('ORDER_NUMBER');
} catch (ZuoraApiException $e) {
// ...
}