Purchase Controller
In order to implement the Purchase API using the SDK, the developer must use the controller class PurchaseController and implement the callbacks of the operations that need to be supported. There are four callbacks that can be set. Of these four callbacks, two must be completed for each billing method.
Bill Once: Purchase
Fulfill purchase: The callback receives a FulfillPurchaseRequest object and returns a FulfillPurchaseResponse and it is set via onFulfillPurchase.
Revoke purchase: The callback receives a RevokePurchaseRequest object and returns a RevokePurchaseResponse and it is set via onRevokePurchase.
Bill Recurring: Subscription
Subscription activate: The callback receives a SubscriptionActivateRequest object and returns a SubscriptionActivateResponse and it is set via onSubscriptionActivate.
Subscription deactivate: The callback receives a SubscriptionDeactivateRequest object and returns a SubscriptionDeactivateResponse and it is set via onSubscriptionDeactivate.
A sample piece of code that uses the PurchaseController controller can be seen here:
$controller = new PurchaseController($credentialStore);
$controller->onFulfillPurchase(function ($req) {
$res = new FulfillPurchaseResponse();
$res->setResponse(FulfillPurchaseValue::OK);
return $res;
});
$controller->onRevokePurchase(function ($req) {
$res = new RevokePurchaseResponse();
$res->setResponse(RevokePurchaseResponseValue::OK);
return $res;
});
$controller->onSubscriptionActivate(function ($req) {
$res = new SubscriptionActivateResponse();
$res->setResponse(SubscriptionActivateResponseValue::OK);
return $res;
});
$controller->onSubscriptionDeactivate(function ($req) {
$res = new SubscriptionDeactivateResponse();
$res->setResponse(SubscriptionDeactivateResponseValue::OK);
return $res;
});
$response = $controller->process($_SERVER);
echo $response;
For those interested in the technical details, the Appendix B explains how to implement a client application to interact with the API, without the SDK