1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196:
<?php
/**
* Fat Zebra REST Create Subscription Request
*/
namespace Omnipay\Fatzebra\Message;
/**
* Fat Zebra REST Create Subscription Request
*
* To create a new subscription the following details are required:
*
* * customer ID (getCustomerReference from a CreateCustomerRequest response)
* * plan ID (getTransactionReference from a CreatePlanRequest response)
* * frequency
* * start_date
* * reference
*
* Example:
*
* <code>
* // Create a gateway for the Fat Zebra REST Gateway
* // (routes to GatewayFactory::create)
* $gateway = Omnipay::create('FatzebraGateway');
*
* // Initialise the gateway
* $gateway->initialize(array(
* 'username' => 'TEST',
* 'token' => 'TEST',
* 'testMode' => true, // Or false when you are ready for live transactions
* ));
*
* // Create a credit card object
* // This card can be used for testing.
* $card = new CreditCard(array(
* 'firstName' => 'Example',
* 'lastName' => 'Customer',
* 'number' => '4005550000000001',
* 'expiryMonth' => '01',
* 'expiryYear' => '2020',
* 'cvv' => '123',
* 'billingAddress1' => '1 Scrubby Creek Road',
* 'billingCountry' => 'AU',
* 'billingCity' => 'Scrubby Creek',
* 'billingPostcode' => '4999',
* 'billingState' => 'QLD',
* 'email' => 'email@example.com',
* ));
*
* // Do a create customer transaction on the gateway
* $transaction = $gateway->createCustomer(array(
* 'transactionReference' => 'TestCustomer',
* 'clientIp' => $_SERVER['REMOTE_ADDR'],
* 'card' => $card,
* ));
* $response = $transaction->send();
* $customer_id = $response->getCustomerReference();
*
* // Do a create plan transaction on the gateway
* $transaction = $gateway->CreatePlan(array(
* 'name' => 'Test Plan',
* 'transactionReference' => 'TestPlan',
* 'description' => 'A plan created for testing',
* 'amount' => '10.00',
* ));
* $response = $transaction->send();
* $plan_id = $response->getTransactionReference();
*
* // Do a create subscription transaction on the gateway
* $transaction = $gateway->createSubscription(array(
* 'customerReference' => $customer_id,
* 'planReference' => $plan_id,
* 'frequency' => $gateway::FREQUENCY_WEEKLY,
* 'startDate' => new \DateTime('tomorrow'),
* 'transactionReference' => 'TestSubscription',
* ));
* $response = $transaction->send();
* if ($response->isSuccessful()) {
* echo "createSubscription transaction was successful!\n";
* $subscription_id = $response->getSubscriptionReference();
* echo "Subscription Reference = " . $subscription_id . "\n";
* }
* </code>
*
* @link http://www.paystream.com.au/developer-guides/
* @see Omnipay\Fatzebra\FatzebraGateway
*/
class CreateSubscriptionRequest extends AbstractRestRequest
{
public function getData()
{
$this->validate('customerReference', 'planReference', 'frequency', 'startDate', 'transactionReference');
$data = array(
'customer' => $this->getCustomerReference(),
'plan' => $this->getPlanReference(),
'frequency' => $this->getFrequency(),
'start_date' => $this->getStartDate()->format('Y-m-d'),
'reference' => $this->getTransactionReference(),
'is_active' => 'true',
);
return $data;
}
/**
* Get transaction endpoint.
*
* Referenceizes are created using the /purchases resource.
*
* @return string
*/
protected function getEndpoint()
{
return parent::getEndpoint() . '/subscriptions';
}
/**
* Get the customer token
*
* @return string
*/
public function getCustomerReference()
{
return $this->getParameter('customerReference');
}
/**
* Set the customer token
*
* @return CreateSubscriptionRequest provides a fluent interface.
*/
public function setCustomerReference($value)
{
return $this->setParameter('customerReference', $value);
}
/**
* Get the plan token
*
* @return string
*/
public function getPlanReference()
{
return $this->getParameter('planReference');
}
/**
* Set the plan token
*
* @return CreateSubscriptionRequest provides a fluent interface.
*/
public function setPlanReference($value)
{
return $this->setParameter('planReference', $value);
}
/**
* Get the frequency
*
* @return string
*/
public function getFrequency()
{
return $this->getParameter('frequency');
}
/**
* Set the frequency
*
* @return CreateSubscriptionRequest provides a fluent interface.
*/
public function setFrequency($value)
{
return $this->setParameter('frequency', $value);
}
/**
* Get the start date
*
* @return \DateTime
*/
public function getStartDate()
{
return $this->getParameter('startDate');
}
/**
* Set the start date
*
* @return CreateSubscriptionRequest provides a fluent interface.
*/
public function setStartDate($value)
{
return $this->setParameter('startDate', $value);
}
}