diff --git a/.gitignore b/.gitignore index 22eafd7e..7c7da39b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.tmproj composer.lock vendor -composer.phar \ No newline at end of file +composer.phar +.idea diff --git a/lib/recurly/addon.php b/lib/recurly/addon.php index 04e6c4fe..9fdd2bb5 100644 --- a/lib/recurly/addon.php +++ b/lib/recurly/addon.php @@ -18,6 +18,7 @@ * @property string $revenue_schedule_type Optional field for setting a revenue schedule type. This will determine how revenue for the associated Plan should be recognized. When creating a Plan, if you supply an end_date and end_date available schedule types are never, evenly, at_range_start, or at_range_end. * @property DateTime $created_at The date and time the add-on was created. * @property DateTime $updated_at The date and time the add-on was last updated. + * @property string $plan_code Unique code to identify the plan. */ class Recurly_Addon extends Recurly_Resource { diff --git a/lib/recurly/base.php b/lib/recurly/base.php index 9ceaa167..4d909af9 100644 --- a/lib/recurly/base.php +++ b/lib/recurly/base.php @@ -6,6 +6,8 @@ abstract class Recurly_Base protected $_type; protected $_client; protected $_links; + protected $_values; + protected $_errors; public function __construct($href = null, $client = null) { @@ -18,6 +20,8 @@ public function __construct($href = null, $client = null) * Request the URI, validate the response and return the object. * @param string Resource URI, if not fully qualified, the base URL will be prepended * @param string Optional client for the request, useful for mocking the client + * @return object Recurly_Resource or null + * @throws Recurly_Error */ public static function _get($uri, $client = null) { @@ -33,6 +37,7 @@ public static function _get($uri, $client = null) * Send a HEAD request to the URI, validate the response and return the headers. * @param string Resource URI, if not fully qualified, the base URL will be prepended * @param string Optional client for the request, useful for mocking the client + * @throws Recurly_Error */ public static function _head($uri, $client = null) { @@ -49,6 +54,8 @@ public static function _head($uri, $client = null) * @param string Resource URI, if not fully qualified, the base URL will be prepended * @param string Data to post to the URI * @param string Optional client for the request, useful for mocking the client + * @return object Recurly_Resource or null + * @throws Recurly_Error */ protected static function _post($uri, $data = null, $client = null) { @@ -66,6 +73,8 @@ protected static function _post($uri, $data = null, $client = null) * Put to the URI, validate the response and return the object. * @param string Resource URI, if not fully qualified, the base URL will be prepended * @param string Optional client for the request, useful for mocking the client + * @return object Recurly_Resource or null + * @throws Recurly_Error */ protected static function _put($uri, $client = null) { @@ -74,6 +83,7 @@ protected static function _put($uri, $client = null) } $response = $client->request(Recurly_Client::PUT, $uri); $response->assertValidResponse(); + $object = null; if ($response->body) { $object = Recurly_Base::__parseResponseToNewObject($response, $uri, $client); } @@ -85,6 +95,8 @@ protected static function _put($uri, $client = null) * Delete the URI, validate the response and return the object. * @param string Resource URI, if not fully qualified, the base URL will be appended * @param string Optional client for the request, useful for mocking the client + * @return object Recurly_Resource or null + * @throws Recurly_Error */ protected static function _delete($uri, $client = null) { diff --git a/lib/recurly/billing_info.php b/lib/recurly/billing_info.php index 41829441..8516dbe8 100644 --- a/lib/recurly/billing_info.php +++ b/lib/recurly/billing_info.php @@ -19,7 +19,6 @@ * @property string $phone Phone number * @property string $company Customer's company * @property string $vat_number Customer's VAT Number - * @property string $currency Currency in which invoices will be posted. Only applicable if this account is enrolled in a plan has a different currency than your site's default. * @property string $verification_value Security code or CVV, 3-4 digits STRONGLY RECOMMENDED * @property string $ip_address Customer's IP address when updating their Billing Information STRONGLY RECOMMENDED * @property string $external_hpp_type Used to indicate payment made out of band via an external service (e.g. Adyen HPP). @@ -28,6 +27,12 @@ */ class Recurly_BillingInfo extends Recurly_Resource { + /** + * @param string $accountCode The account code + * @param Recurly_Client $client The recurly client + * @return object Recurly_Resource or null + * @throws Recurly_Error + */ public static function get($accountCode, $client = null) { return Recurly_Base::_get(Recurly_BillingInfo::uriForBillingInfo($accountCode), $client); } @@ -35,17 +40,34 @@ public static function get($accountCode, $client = null) { public function create() { $this->update(); } + + /** + * @throws Recurly_Error + */ public function update() { $this->_save(Recurly_Client::PUT, $this->uri()); } + /** + * @throws Recurly_Error + */ public function delete() { return Recurly_Base::_delete($this->uri(), $this->_client); } + + /** + * @param string $accountCode The account code + * @param Recurly_Client $client The recurly client + * @return object Recurly_Resource or null + * @throws Recurly_Error + */ public static function deleteForAccount($accountCode, $client = null) { return Recurly_Base::_delete(Recurly_BillingInfo::uriForBillingInfo($accountCode), $client); } + /** + * @throws Recurly_Error + */ protected function uri() { if (!empty($this->_href)) return $this->getHref(); diff --git a/lib/recurly/client.php b/lib/recurly/client.php index ab61855d..0ab30993 100644 --- a/lib/recurly/client.php +++ b/lib/recurly/client.php @@ -85,6 +85,13 @@ function __construct($apiKey = null, $acceptLanguage = 'en-US') { $this->_acceptLanguage = $acceptLanguage; } + /** + * @param string $method The HTTP method + * @param string $uri The URI + * @param string $data XML string to post to the URI + * @return Recurly_ClientResponse + * @throws Recurly_Error + */ public function request($method, $uri, $data = null) { return $this->_sendRequest($method, $uri, $data); @@ -103,14 +110,16 @@ public function apiKey() { } /** - * Sends an HTTP request to the Recurly API - * - * @param string $method Specifies the HTTP method to be used for this request - * @param string $uri Target URI for this request (relative to the API root) - * @param mixed $data x-www-form-urlencoded data (or array) to be sent in a POST request body - * - * @return $code, $response - */ + * Sends an HTTP request to the Recurly API + * + * @param string $method Specifies the HTTP method to be used for this request + * @param string $uri Target URI for this request (relative to the API root) + * @param mixed $data x-www-form-urlencoded data (or array) to be sent in a POST request body + * + * @return Recurly_ClientResponse + * + * @throws Recurly_Error + */ private function _sendRequest($method, $uri, $data = '') { if(function_exists('mb_internal_encoding')) @@ -200,6 +209,11 @@ private function _getHeaders($headerText) return $returnHeaders; } + /** + * @param int $errorNumber The curl error number + * @param string $message The error message + * @throws Recurly_Error + */ private function _raiseCurlError($errorNumber, $message) { switch ($errorNumber) { @@ -220,6 +234,7 @@ private function _raiseCurlError($errorNumber, $message) * * @param string $uri Target URI for the request (complete URL) * @param resource $file_pointer Resourced returned from fopen() with write mode. + * @throws Recurly_Error */ public function getFile($uri, $file_pointer) { $ch = curl_init(); @@ -254,6 +269,7 @@ public function getFile($uri, $file_pointer) { * @param string $uri Target URI for this request (relative to the API root) * @param string $locale Locale for the PDF invoice (e.g. "en-GB", "en-US", "fr") * @return string $response PDF document + * @throws Recurly_Error */ public function getPdf($uri, $locale = null) { diff --git a/lib/recurly/coupon.php b/lib/recurly/coupon.php index afb5f7b3..4d79ae87 100644 --- a/lib/recurly/coupon.php +++ b/lib/recurly/coupon.php @@ -28,6 +28,7 @@ * @property DateTime $created_at The date and time the coupon was created. * @property DateTime $updated_at The date and time the coupon was last updated. * @property DateTime $deleted_at The date and time the coupon was deleted. + * @property string $state The state of coupons to return: redeemable, expired, maxed_out, or inactive. */ class Recurly_Coupon extends Recurly_Resource { @@ -38,6 +39,12 @@ function __construct($href = null, $client = null) { $this->discount_in_cents = new Recurly_CurrencyList('discount_in_cents'); } + /** + * @param string $couponCode The coupon code + * @param Recurly_Client $client The recurly client + * @return object Recurly_Resource or null + * @throws Recurly_Error + */ public static function get($couponCode, $client = null) { return Recurly_Base::_get(Recurly_Coupon::uriForCoupon($couponCode), $client); } @@ -46,6 +53,13 @@ public function create() { $this->_save(Recurly_Client::POST, Recurly_Client::PATH_COUPONS); } + /** + * @param string $accountCode The account code + * @param string $currency The currency of + * @param string $subscriptionUUID The UUID of the subscription + * @return Recurly_CouponRedemption + * @throws Recurly_Error + */ public function redeemCoupon($accountCode, $currency, $subscriptionUUID = null) { if ($this->state != 'redeemable') { throw new Recurly_Error('Coupon is not redeemable.'); @@ -62,6 +76,8 @@ public function redeemCoupon($accountCode, $currency, $subscriptionUUID = null) return $redemption; } } + + return null; } public function update() { @@ -72,9 +88,20 @@ public function restore() { $this->_save(Recurly_Client::PUT, $this->uri() . '/restore', $this->createUpdateXML()); } + /** + * @return object + * @throws Recurly_Error + */ public function delete() { return Recurly_Base::_delete($this->uri(), $this->_client); } + + /** + * @param string $couponCode The coupon code + * @param Recurly_Client $client The recurly client + * @return object Recurly_Resource or null + * @throws Recurly_Error + */ public static function deleteCoupon($couponCode, $client = null) { return Recurly_Base::_delete(Recurly_Coupon::uriForCoupon($couponCode), $client); } @@ -99,6 +126,11 @@ public function createUpdateXML() { return $this->renderXML($doc); } + /** + * @param int $number Number of unique codes to generate + * @return array + * @throws Recurly_Error + */ public function generate($number) { $doc = $this->createDocument(); diff --git a/lib/recurly/custom_field.php b/lib/recurly/custom_field.php index e6678424..22be44a2 100644 --- a/lib/recurly/custom_field.php +++ b/lib/recurly/custom_field.php @@ -2,6 +2,8 @@ /** * An name/value pair. + * @property string $name The name of the custom field + * @property string $value The value of the custom field */ class Recurly_CustomField extends Recurly_Resource { diff --git a/lib/recurly/custom_field_list.php b/lib/recurly/custom_field_list.php index d22622ed..2607e184 100644 --- a/lib/recurly/custom_field_list.php +++ b/lib/recurly/custom_field_list.php @@ -5,6 +5,11 @@ // values are used to clear a value. class Recurly_CustomFieldList extends ArrayObject { + /** + * @param mixed $index + * @param object $value Must be instance of Recurly_CustomField + * @throws Exception + */ public function offsetSet($index, $value) { if (!$value instanceof Recurly_CustomField) { throw new Exception("value must be an instance of Recurly_CustomField"); diff --git a/lib/recurly/export_date_list.php b/lib/recurly/export_date_list.php index cdaddcc1..4e20f31a 100644 --- a/lib/recurly/export_date_list.php +++ b/lib/recurly/export_date_list.php @@ -4,6 +4,9 @@ class Recurly_ExportDateList extends Recurly_Pager { /** * Fetch a list of dates that have exports. + * @param array $params An array of parameters to include with the request + * @param Recurly_Client $client The recurly client + * @return Recurly_ExportDateList */ public static function get($params = null, $client = null) { return new self(self::_uriWithParams('/export_dates', $params), $client); diff --git a/lib/recurly/export_file.php b/lib/recurly/export_file.php index 01cc0b34..b091313d 100644 --- a/lib/recurly/export_file.php +++ b/lib/recurly/export_file.php @@ -6,7 +6,9 @@ class Recurly_ExportFile extends Recurly_Resource * Look up a file by date and name. * @param string date * @param string name - * @return Recurly_ExportFile + * @param Recurly_Client $client + * @return object Recurly_ExportFile + * @throws Recurly_Error */ public static function get($date, $name, $client = null) { return self::_get('/export_dates/' . rawurlencode($date) . '/export_files/' . rawurlencode($name), $client); @@ -24,6 +26,7 @@ protected function getWriteableAttributes() { * Download the file. * * @param resource $file_pointer Resourced returned from fopen() with write mode. + * @throws Recurly_Error */ function download($file_pointer) { if (empty($this->download_url)) { diff --git a/lib/recurly/export_file_list.php b/lib/recurly/export_file_list.php index 0fc465e7..f4786522 100644 --- a/lib/recurly/export_file_list.php +++ b/lib/recurly/export_file_list.php @@ -6,6 +6,8 @@ class Recurly_ExportFileList extends Recurly_Pager * Fetch a list of export files for a given date. * * @param string $date Date in YYYY-MM-DD format. + * @param array $params An array of parameters to include with the request + * @param Recurly_Client $client The recurly client * @return Recurly_ExportFileList */ public static function get($date, $params = null, $client = null) { diff --git a/lib/recurly/gift_card.php b/lib/recurly/gift_card.php index d3841d03..a71ab956 100644 --- a/lib/recurly/gift_card.php +++ b/lib/recurly/gift_card.php @@ -23,6 +23,11 @@ class Recurly_GiftCard extends Recurly_Resource { /** * Get a gift card by the id + * + * @param string $giftCardId The gift card ID + * @param Recurly_Client $client The recurly client + * @return object Recurly_Resource or null + * @throws Recurly_Error */ public static function get($giftCardId, $client = null) { return Recurly_Base::_get(Recurly_GiftCard::uriForGiftCard($giftCardId), $client); @@ -30,6 +35,10 @@ public static function get($giftCardId, $client = null) { /** * Redeem a gift card given an account code + * + * @param string $accountCode The account code + * + * @throws Recurly_Error */ public function redeem($accountCode) { $doc = $this->createDocument(); @@ -48,7 +57,7 @@ public function create() { * Preview the creation and check for errors. * * Note: once preview() has been called you will not be able to call create() - * without reassiging all the attributes. + * without reassigning all the attributes. */ public function preview() { $this->_save(Recurly_Client::POST, Recurly_Client::PATH_GIFT_CARDS . '/preview'); diff --git a/lib/recurly/invoice.php b/lib/recurly/invoice.php index c1f894a5..26d8b463 100644 --- a/lib/recurly/invoice.php +++ b/lib/recurly/invoice.php @@ -37,7 +37,7 @@ * @property Recurly_Stub $redemptions * @property Recurly_Adjustment[] $line_items * @property Recurly_TransactionList $transactions - * @property Recurly_String $all_transactions A link to all transactions on the invoice. Only present if there are more than 500 transactions + * @property string $all_transactions A link to all transactions on the invoice. Only present if there are more than 500 transactions * @property int $subtotal_before_discount_in_cents The total of all adjustments on the invoice before discounts or taxes are applied. * @property int $credit_customer_notes Allows merchant to set customer notes on a credit invoice. Will only be rejected if type is set to "charge", otherwise will be ignored if no credit invoice is created. */ @@ -45,15 +45,23 @@ class Recurly_Invoice extends Recurly_Resource { /** * Lookup an invoice by its ID + * * @param string Invoice number - * @return Recurly_Invoice invoice + * @param Recurly_Client $client The recurly client + * @return object Recurly_Invoice + * @throws Recurly_Error */ public static function get($invoiceNumber, $client = null) { return self::_get(Recurly_Invoice::uriForInvoice($invoiceNumber), $client); } /** + * * Retrieve the PDF version of this invoice + * + * @param string $locale + * @return string + * @throws Recurly_Error */ public function getPdf($locale = null) { return Recurly_Invoice::getInvoicePdf($this->invoiceNumberWithPrefix(), $locale, $this->_client); @@ -61,6 +69,12 @@ public function getPdf($locale = null) { /** * Retrieve the PDF version of an invoice + * + * @param $invoiceNumber + * @param string $locale + * @param Recurly_Client $client The recurly client + * @return string + * @throws Recurly_Error */ public static function getInvoicePdf($invoiceNumber, $locale = null, $client = null) { $uri = self::uriForInvoice($invoiceNumber); @@ -73,10 +87,13 @@ public static function getInvoicePdf($invoiceNumber, $locale = null, $client = n /** * Creates an invoice for an account using its pending charges - * @param string Unique account code - * @param array additional invoice attributes (see writeableAttributes) - * @return Recurly_InvoiceCollection collection of invoices on success - **/ + * + * @param string $accountCode Unique account code + * @param array $attributes additional invoice attributes (see writeableAttributes) + * @param Recurly_Client $client the recurly client + * @return object Recurly_InvoiceCollection collection of invoices on success + * @throws Recurly_Error + */ public static function invoicePendingCharges($accountCode, $attributes = array(), $client = null) { $uri = Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_INVOICES; $invoice = new self(); @@ -85,9 +102,11 @@ public static function invoicePendingCharges($accountCode, $attributes = array() /** * Previews an invoice for an account using its pending charges - * @param string Unique account code - * @param array additional invoice attributes (see writeableAttributes) - * @return Recurly_InvoiceCollection collection of invoices on success + * @param string $accountCode Unique account code + * @param array $attributes additional invoice attributes (see writeableAttributes) + * @param Recurly_Client $client the recurly client + * @return object Recurly_InvoiceCollection collection of invoices on success + * @throws Recurly_Error */ public static function previewPendingCharges($accountCode, $attributes = array(), $client = null) { $uri = Recurly_Client::PATH_ACCOUNTS . '/' . rawurlencode($accountCode) . Recurly_Client::PATH_INVOICES . '/preview'; @@ -95,18 +114,30 @@ public static function previewPendingCharges($accountCode, $attributes = array() return Recurly_InvoiceCollection::_post($uri, $invoice->setValues($attributes)->xml(), $client); } + /** + * @throws Recurly_Error + */ public function markSuccessful() { $this->_save(Recurly_Client::PUT, $this->uri() . '/mark_successful'); } + /** + * @throws Recurly_Error + */ public function forceCollect() { $this->_save(Recurly_Client::PUT, $this->uri() . '/collect'); } + /** + * @throws Recurly_Error + */ public function void() { $this->_save(Recurly_Client::PUT, $this->uri() . '/void'); } + /** + * @throws Recurly_Error + */ public function markFailed() { return Recurly_InvoiceCollection::_put($this->uri() . '/mark_failed', $this->_client); } @@ -117,8 +148,9 @@ public function invoiceNumberWithPrefix() { /** * Enters an offline payment for an invoice - * @param Recurly_Transaction additional transaction attributes. The attributes available to set are (payment_method, collected_at, amount_in_cents, description) - * @return Recurly_Transaction transaction on success + * @param $transaction Recurly_Transaction additional transaction attributes. The attributes available to set are (payment_method, collected_at, amount_in_cents, description) + * @return object Recurly_Transaction transaction on success + * @throws Recurly_Error */ public function enterOfflinePayment($transaction) { $uri = $this->uri() . '/transactions'; @@ -127,9 +159,10 @@ public function enterOfflinePayment($transaction) { /** * Refunds an open amount from the invoice and returns a collection of refund invoices - * @param Integer amount in cents to refund from this invoice - * @param String indicates the refund order to apply, valid options: {'credit_first','transaction_first'}, defaults to 'credit_first' - * @return Recurly_Invoice a new refund invoice + * @param int $amount_in_cents amount in cents to refund from this invoice + * @param string $refund_method indicates the refund order to apply, valid options: {'credit_first','transaction_first'}, defaults to 'credit_first' + * @return object Recurly_Invoice a new refund invoice + * @throws Recurly_Error */ public function refundAmount($amount_in_cents, $refund_method = 'credit_first') { $doc = $this->createDocument(); @@ -142,10 +175,13 @@ public function refundAmount($amount_in_cents, $refund_method = 'credit_first') } /** + * * Refunds given line items from an invoice and returns new refund invoice - * @param Array refund attributes or Array of refund attributes to refund (see 'REFUND ATTRIBUTES' in docs or Recurly_Adjustment#toRefundAttributes) - * @param String indicates the refund order to apply, valid options: {'credit_first','transaction_first'}, defaults to 'credit_first' - * @return Recurly_Invoice a new refund invoice + * + * @param array $line_items refund attributes or Array of refund attributes to refund (see 'REFUND ATTRIBUTES' in docs or Recurly_Adjustment#toRefundAttributes) + * @param string $refund_method indicates the refund order to apply, valid options: {'credit_first','transaction_first'}, defaults to 'credit_first' + * @return object Recurly_Invoice a new refund invoice + * @throws Recurly_Error */ public function refund($line_items, $refund_method = 'credit_first') { if (isset($line_items['uuid'])) { $line_items = array($line_items); } @@ -168,11 +204,18 @@ public function refund($line_items, $refund_method = 'credit_first') { /** * Attempts to update an invoice + * + * @throws Recurly_Error */ public function update() { $this->_save(Recurly_Client::PUT, $this->uri()); } + /** + * @param string $xml_string + * @return object Recurly_Invoice + * @throws Recurly_Error + */ protected function createRefundInvoice($xml_string) { return Recurly_Invoice::_post($this->uri() . '/refund', $xml_string, $this->_client); } @@ -186,6 +229,11 @@ protected function getWriteableAttributes() { 'collection_method', 'net_terms', 'po_number', 'currency', 'credit_customer_notes' ); } + + /** + * @return null|string + * @throws Recurly_Error + */ protected function uri() { $invoiceNumberWithPrefix = $this->invoiceNumberWithPrefix(); if (!empty($this->_href)) diff --git a/lib/recurly/measured_unit.php b/lib/recurly/measured_unit.php index 6ffa85a9..0acdbe19 100644 --- a/lib/recurly/measured_unit.php +++ b/lib/recurly/measured_unit.php @@ -13,6 +13,12 @@ public function create() { $this->_save(Recurly_Client::POST, Recurly_Client::PATH_MEASURED_UNITS); } + /** + * @param $id + * @param Recurly_Client $client + * @return object + * @throws Recurly_Error + */ public static function get($id, $client = null) { return Recurly_Base::_get(Recurly_MeasuredUnit::uriForMeasuredUnit($id), $client); } @@ -21,7 +27,7 @@ protected function uri() { if (!empty($this->_href)) return $this->getHref(); else - return Recurly_Addon::uriForMeasuredUnit($this->id); + return Recurly_MeasuredUnit::uriForMeasuredUnit($this->id); } protected static function uriForMeasuredUnit($id) { return Recurly_Client::PATH_MEASURED_UNITS . '/' . rawurlencode($id); diff --git a/lib/recurly/pager.php b/lib/recurly/pager.php index 21bdfdf7..6fbb34a8 100644 --- a/lib/recurly/pager.php +++ b/lib/recurly/pager.php @@ -16,6 +16,7 @@ abstract class Recurly_Pager extends Recurly_Base implements Iterator, Countable * all records. Otherwise it'll return the count of the cached _objects. * * @return integer number of records in list + * @throws Recurly_Error */ public function count() { if (isset($this->_href)) { @@ -32,6 +33,8 @@ public function count() { /** * Rewind to the beginning + * + * @throws Recurly_Error */ public function rewind() { $this->_loadFrom($this->_href); @@ -40,7 +43,9 @@ public function rewind() { /** * The current object + * * @return Recurly_Resource the current object + * @throws Recurly_Error */ public function current() { @@ -85,6 +90,9 @@ public function valid() { /** * Load another page of results into this pager. + * + * @param $uri + * @throws Recurly_Error */ protected function _loadFrom($uri) { if (empty($uri)) { @@ -115,6 +123,8 @@ protected static function _setState($params, $state) { /** * The 'Links' header contains links to the next, previous, and starting pages. * This parses the links header into an array of links if the header is present. + * + * @param $response */ private function _loadLinks($response) { $this->_links = array(); diff --git a/lib/recurly/plan.php b/lib/recurly/plan.php index 6beca28a..4842e50b 100644 --- a/lib/recurly/plan.php +++ b/lib/recurly/plan.php @@ -22,12 +22,9 @@ * @property string $cancel_url Deprecated URL to redirect to on canceled signup on the hosted payment pages. * @property boolean $tax_exempt true exempts tax on the plan, false applies tax on the plan. If not defined, then defaults to the Plan and Site settings. * @property string $tax_code Optional field for EU VAT merchants and Avalara AvaTax Pro merchants. If you are using Recurly's EU VAT feature, you can use values of unknown, physical, or digital. If you have your own AvaTax account configured, you can use Avalara tax codes to assign custom tax rules. - * @property string $plan_code The unique plan code * @property string $add_on_code Add-on code. Max of 50 characters. * @property string $add_on_type Whether the add-on is Fixed-Price (fixed), or Usage-Based (usage). * @property integer $default_quantity Default quantity for the hosted pages. - * @property Recurly_CurrencyList $unit_amount_in_cents Array of unit amounts with their currency code. Max 10000000. - * @property string $name Add-on name. Max of 255 characters. * @property boolean $display_quantity_on_hosted_page If true, display a quantity field on the hosted pages for the add-on. * @property boolean $optional Whether the add-on is optional for the customer to include in their purchase on the hosted payment page. * @property string $measured_unit_id The id of the measured unit on your site associated with the add-on. @@ -44,6 +41,12 @@ function __construct($href = null, $client = null) { $this->unit_amount_in_cents = new Recurly_CurrencyList('unit_amount_in_cents'); } + /** + * @param string $planCode The plan code + * @param Recurly_Client $client The recurly client + * @return object Recurly_Resource or null + * @throws Recurly_Error + */ public static function get($planCode, $client = null) { return Recurly_Base::_get(Recurly_Plan::uriForPlan($planCode), $client); } @@ -55,9 +58,20 @@ public function update() { $this->_save(Recurly_Client::PUT, $this->uri()); } + /** + * @return object + * @throws Recurly_Error + */ public function delete() { return Recurly_Base::_delete($this->uri(), $this->_client); } + + /** + * @param string $planCode The plan code + * @param Recurly_Client $client The recurly client + * @return object Recurly_Resource or null + * @throws Recurly_Error + */ public static function deletePlan($planCode, $client = null) { return Recurly_Base::_delete(Recurly_Plan::uriForPlan($planCode), $client); } diff --git a/lib/recurly/purchase.php b/lib/recurly/purchase.php index 54633cc4..6e877b95 100644 --- a/lib/recurly/purchase.php +++ b/lib/recurly/purchase.php @@ -21,9 +21,10 @@ class Recurly_Purchase extends Recurly_Resource /** * Send the purchase data to the server and creates an invoice. * - * @param Recurly_Purchase Our purchase data. - * @param RecurlyClient Optional client for the request, useful for mocking the client - * @return Recurly_InvoiceCollection + * @param $purchase Recurly_Purchase Our purchase data. + * @param Recurly_Client $client Optional client for the request, useful for mocking the client + * @return object Recurly_InvoiceCollection + * @throws Recurly_Error */ public static function invoice($purchase, $client = null) { return Recurly_Base::_post('/purchases', $purchase->xml(), $client); @@ -33,9 +34,10 @@ public static function invoice($purchase, $client = null) { * Send the purchase data to the server and create a preview invoice. This runs * the validations but not the transactions. * - * @param Recurly_Purchase Our purchase data. - * @param RecurlyClient Optional client for the request, useful for mocking the client - * @return Recurly_InvoiceCollection + * @param $purchase Recurly_Purchase Our purchase data. + * @param Recurly_Client $client Optional client for the request, useful for mocking the client + * @return object Recurly_InvoiceCollection + * @throws Recurly_Error */ public static function preview($purchase, $client = null) { return Recurly_Base::_post('/purchases/preview', $purchase->xml(), $client); @@ -48,9 +50,10 @@ public static function preview($purchase, $client = null) { * has been completed on an external source (e.g. Adyen's Hosted * Payment Pages). * - * @param Recurly_Purchase Our purchase data. - * @param RecurlyClient Optional client for the request, useful for mocking the client - * @return Recurly_InvoiceCollection + * @param $purchase Recurly_Purchase Our purchase data. + * @param Recurly_Client $client Optional client for the request, useful for mocking the client + * @return object Recurly_InvoiceCollection + * @throws Recurly_Error */ public static function authorize($purchase, $client = null) { return Recurly_Base::_post('/purchases/authorize', $purchase->xml(), $client); @@ -60,9 +63,10 @@ public static function authorize($purchase, $client = null) { * Use for Adyen HPP transaction requests. This runs * the validations but not the transactions. * - * @param Recurly_Purchase Our purchase data. - * @param RecurlyClient Optional client for the request, useful for mocking the client - * @return Recurly_InvoiceCollection + * @param $purchase Recurly_Purchase Our purchase data. + * @param Recurly_Client $client Optional client for the request, useful for mocking the client + * @return object Recurly_InvoiceCollection + * @throws Recurly_Error */ public static function pending($purchase, $client = null) { return Recurly_Base::_post('/purchases/pending', $purchase->xml(), $client); diff --git a/lib/recurly/push_notification.php b/lib/recurly/push_notification.php index 408ac308..9b323c40 100644 --- a/lib/recurly/push_notification.php +++ b/lib/recurly/push_notification.php @@ -86,6 +86,10 @@ class Recurly_PushNotification var $subscription; var $transaction; var $invoice; + var $credit_payment; + var $gift_card; + var $shipping_address; + var $usage; function __construct($post_xml) { diff --git a/lib/recurly/recurly_js.php b/lib/recurly/recurly_js.php index 6d38a36a..d04afc9c 100644 --- a/lib/recurly/recurly_js.php +++ b/lib/recurly/recurly_js.php @@ -13,6 +13,11 @@ class Recurly_js private $data; + /** + * Recurly_js constructor. + * @param $data + * @throws Exception + */ function __construct($data) { if (!is_array($data)) { @@ -22,7 +27,12 @@ function __construct($data) $this->data = $data; } - // Create a signature with the protected data + /** + * Create a signature with the protected data + * + * @return string + * @throws Recurly_ConfigurationError + */ public function get_signature() { $this->data['timestamp'] = $this->utc_timestamp(); @@ -47,14 +57,27 @@ public static function sign($data, $type = "Recurly_js") return $rjs->get_signature(); } - // Lookup the result of a Recurly.js operation + /** + * Lookup the result of a Recurly.js operation + * + * @param $token + * @param null $client + * @return object + * @throws Recurly_Error + */ public static function fetch($token, $client = null) { $uri = Recurly_Client::PATH_RECURLY_JS_RESULT . '/' . rawurlencode($token); return Recurly_Base::_get($uri, $client); } - // Hash a message using the client's private key + /** + * Hash a message using the client's private key + * + * @param $message + * @return string + * @throws Recurly_ConfigurationError + */ public static function _hash($message) { if (!isset(Recurly_js::$privateKey) || strlen(Recurly_js::$privateKey) != 32) { diff --git a/lib/recurly/redemption.php b/lib/recurly/redemption.php index 2a71d860..93441b46 100644 --- a/lib/recurly/redemption.php +++ b/lib/recurly/redemption.php @@ -13,15 +13,28 @@ * @property string $coupon_code The coupon code of the coupon used. * @property DateTime $created_at The date and time the redemption was created in Recurly. * @property DateTime $updated_at The date and time the redemption was last updated. + * @property string $account_code The account code + * @property string $subscription_uuid The subscription UUID */ class Recurly_CouponRedemption extends Recurly_Resource { protected static $_redeemUrl; + /** + * @param string $accountCode The account code + * @param Recurly_Client $client The recurly client + * @return object + * @throws Recurly_Error + */ public static function get($accountCode, $client = null) { return Recurly_Base::_get(Recurly_CouponRedemption::uriForAccount($accountCode), $client); } + /** + * @param string $accountCode The account code + * @return object + * @throws Recurly_Error + */ public function delete($accountCode = null) { return Recurly_Base::_delete($this->uri($accountCode), $this->_client); } diff --git a/lib/recurly/resource.php b/lib/recurly/resource.php index 6f421c41..266af36f 100644 --- a/lib/recurly/resource.php +++ b/lib/recurly/resource.php @@ -66,8 +66,8 @@ public function getErrors() { /** * Does a mass assignment on this resource's values * - * @param array - * The array of values to set on the resource. + * @param array $values The array of values to set on the resource. + * @return $this */ public function setValues($values) { foreach($values as $key => $value) { @@ -76,6 +76,12 @@ public function setValues($values) { return $this; } + /** + * @param string $method + * @param string $uri + * @param string $data + * @throws Recurly_Error + */ protected function _save($method, $uri, $data = null) { $this->_errors = array(); // reset errors diff --git a/lib/recurly/response.php b/lib/recurly/response.php index e06b5138..b0e3bf94 100644 --- a/lib/recurly/response.php +++ b/lib/recurly/response.php @@ -12,6 +12,10 @@ function __construct($statusCode, $headers, $body) { $this->body = $body; } + /** + * @param $object + * @throws Recurly_ValidationError + */ public function assertSuccessResponse($object) { if ($this->statusCode == 422) @@ -39,6 +43,9 @@ public function assertSuccessResponse($object) } } + /** + * @throws Recurly_Error + */ public function assertValidResponse() { if (!empty($this->headers['Recurly-Deprecated'])) { diff --git a/lib/recurly/shipping_address.php b/lib/recurly/shipping_address.php index 9ad58b7a..cbc1ac38 100644 --- a/lib/recurly/shipping_address.php +++ b/lib/recurly/shipping_address.php @@ -2,6 +2,9 @@ class Recurly_ShippingAddress extends Recurly_Resource { + /** + * @throws Recurly_Error + */ public function update() { $this->_save(Recurly_Client::PUT, $this->getHref()); } diff --git a/lib/recurly/stub.php b/lib/recurly/stub.php index e8add299..fdf18917 100644 --- a/lib/recurly/stub.php +++ b/lib/recurly/stub.php @@ -18,6 +18,10 @@ function __construct($objectType, $href, $client = null) /** * Retrieve the stubbed resource. + * + * @param array $params + * @return object + * @throws Recurly_Error */ function get($params = null) { $uri = self::_uriWithParams($this->_href, $params); diff --git a/lib/recurly/subscription.php b/lib/recurly/subscription.php index 0c75fd6e..e3f7013c 100644 --- a/lib/recurly/subscription.php +++ b/lib/recurly/subscription.php @@ -39,6 +39,9 @@ * @property DateTime $next_bill_date Previously named next_renewal_date. Specifies a future date that the subscription’s next billing period should be billed. * @property DateTime $current_term_started_at Start date of the subscription’s current term. Will equal the future start date if subscription was created in the future state. * @property DateTime $current_term_ends_at End date of the subscription’s current term. Will be null if subscription has future start date. + * @property Recurly_CustomFieldList $custom_fields Optional custom fields for the subscription. + * @property string $uuid Subscription's unique identifier. + * @property string $timeframe now for immediate, renewal to perform when the subscription renews. Defaults to now. */ class Recurly_Subscription extends Recurly_Resource { @@ -48,10 +51,19 @@ public function __construct($href = null, $client = null) { $this->custom_fields = new Recurly_CustomFieldList(); } + /** + * @param $uuid + * @param Recurly_Client $client + * @return object + * @throws Recurly_Error + */ public static function get($uuid, $client = null) { return Recurly_Base::_get(Recurly_Subscription::uriForSubscription($uuid), $client); } + /** + * @throws Recurly_Error + */ public function create() { $this->_save(Recurly_Client::POST, Recurly_Client::PATH_SUBSCRIPTIONS); } @@ -61,6 +73,8 @@ public function create() { * * Note: once preview() has been called you will not be able to call create() * or save() without reassiging all the attributes. + * + * @throws Recurly_Error */ public function preview() { if ($this->uuid) { @@ -72,13 +86,18 @@ public function preview() { /** * Cancel the subscription; it will remain active until it renews. + * + * @throws Recurly_Error */ public function cancel() { $this->_save(Recurly_Client::PUT, $this->uri() . '/cancel'); } + /** * Reactivate a canceled subscription. The subscription will return back to the active, * auto renewing state. + * + * @throws Recurly_Error */ public function reactivate() { $this->_save(Recurly_Client::PUT, $this->uri() . '/reactivate'); @@ -86,6 +105,8 @@ public function reactivate() { /** * Make an update that takes effect immediately. + * + * @throws Recurly_Error */ public function updateImmediately() { $this->timeframe = 'now'; @@ -94,6 +115,8 @@ public function updateImmediately() { /** * Make an update that applies when the subscription renews. + * + * @throws Recurly_Error */ public function updateAtRenewal() { $this->timeframe = 'renewal'; @@ -103,22 +126,33 @@ public function updateAtRenewal() { /** * Terminate the subscription immediately and issue a full refund of the last renewal + * + * @throws Recurly_Error */ public function terminateAndRefund() { $this->terminate('full'); } /** * Terminate the subscription immediately and issue a prorated/partial refund of the last renewal + * + * @throws Recurly_Error */ public function terminateAndPartialRefund() { $this->terminate('partial'); } /** * Terminate the subscription immediately without a refund + * + * @throws Recurly_Error */ public function terminateWithoutRefund() { $this->terminate('none'); } + + /** + * @param $refundType + * @throws Recurly_Error + */ private function terminate($refundType) { $this->_save(Recurly_Client::PUT, $this->uri() . '/terminate?refund=' . $refundType); } @@ -126,9 +160,10 @@ private function terminate($refundType) { /** * Postpone a subscription's renewal date. * - * @param String ISO8601 DateTime String, postpone the subscription to this date - * @param Boolean bulk is for making bulk updates, setting to true bypasses api check for accidental duplicate subscriptions. - **/ + * @param string $nextRenewalDate ISO8601 DateTime String, postpone the subscription to this date + * @param bool $bulk for making bulk updates, setting to true bypasses api check for accidental duplicate subscriptions. + * @throws Recurly_Error + */ public function postpone($nextRenewalDate, $bulk = false) { $this->_save(Recurly_Client::PUT, $this->uri() . '/postpone?next_renewal_date=' . $nextRenewalDate . '&bulk=' . ((bool) $bulk)); } @@ -136,27 +171,29 @@ public function postpone($nextRenewalDate, $bulk = false) { /** * Updates the notes fields of the subscription without generating a SubscriptionChange. * - * @param array of notes, allowed keys: (customer_notes, terms_and_conditions, vat_reverse_charge_notes) - **/ + * @param array $notes Array of notes, allowed keys: (customer_notes, terms_and_conditions, vat_reverse_charge_notes) + * @throws Recurly_Error + */ public function updateNotes($notes) { $this->setValues($notes)->_save(Recurly_Client::PUT, $this->uri() . '/notes'); } /** - * Pauses a subscription or cancels a scheduled pause. - * - * - For an active subscription without a pause scheduled already, - * this will schedule a pause period to begin at the next renewal - * date for the specified number of billing cycles (remaining_pause_cycles). - * - For an active subscription with a scheduled pause, this will update the remaining - * pause cycles with the new value sent. When zero (0) remaining_pause_cycles - * is sent for a subscription with a scheduled pause, the pause will be canceled. - * - For a paused subscription, the remaining_pause_cycles will adjust the - * length of the current pause period. Sending zero (0) in the remaining_pause_cycles - * field will cause the subscription to be resumed at the next renewal date. - * - * @param integer remaining_pause_cycles The number of billing cycles that the subscription will be paused. - **/ + * Pauses a subscription or cancels a scheduled pause. + * + * - For an active subscription without a pause scheduled already, + * this will schedule a pause period to begin at the next renewal + * date for the specified number of billing cycles (remaining_pause_cycles). + * - For an active subscription with a scheduled pause, this will update the remaining + * pause cycles with the new value sent. When zero (0) remaining_pause_cycles + * is sent for a subscription with a scheduled pause, the pause will be canceled. + * - For a paused subscription, the remaining_pause_cycles will adjust the + * length of the current pause period. Sending zero (0) in the remaining_pause_cycles + * field will cause the subscription to be resumed at the next renewal date. + * + * @param integer $remaining_pause_cycles The number of billing cycles that the subscription will be paused. + * @throws Recurly_Error + */ public function pause($remaining_pause_cycles) { $doc = $this->createDocument(); $root = $doc->appendChild($doc->createElement($this->getNodeName())); @@ -171,7 +208,9 @@ public function pause($remaining_pause_cycles) { * from the pause, produce an invoice, and return the newly resumed subscription. * Any at-renewal subscription changes will be immediately applied * when the subscription resumes. - **/ + * + * @throws Recurly_Error + */ public function resume() { $this->_save(Recurly_Client::PUT, $this->uri() . '/resume'); } @@ -184,6 +223,10 @@ public function usages($addOnCode, $params = null) { return Recurly_UsageList::get($this->uuid, $addOnCode, $params); } + /** + * @return null|string + * @throws Recurly_Error + */ protected function uri() { if (!empty($this->_href)) return $this->getHref(); diff --git a/lib/recurly/transaction.php b/lib/recurly/transaction.php index 58b27d26..c14a3dc7 100644 --- a/lib/recurly/transaction.php +++ b/lib/recurly/transaction.php @@ -11,7 +11,6 @@ * @property integer $tax_in_cents Amount of tax or VAT within the transaction, in cents. * @property string $currency 3-letter currency for the transaction. * @property string $status success, declined, or void. - * @property string $payment_method credit_card, paypal, check, wire_transfer, money_order. * @property string $reference Transaction reference from your payment gateway. * @property string $source Source of the transaction. Possible values: transaction for one-time transactions, subscription for subscriptions, billing_info for updating billing info. * @property boolean $recurring True if transaction is recurring. @@ -31,29 +30,36 @@ * @property string $merchant_message For declined transactions, the message displayed to the merchant (if applicable). * @property string $customer_message For declined transactions, the message displayed to the customer (if applicable). * @property string $gateway_error_code For declined transactions, this field lists the gateway error code sent to us from the gateway (if applicable). - * @property string $payment_method The method of payment: The method of payment: (credit_card, paypal, eft, wire_transfer, money_order, check, or other). + * @property string $payment_method The method of payment: (credit_card, paypal, eft, wire_transfer, money_order, check, or other). * @property DateTime $collected_at Date payment was collected * @property string $product_code Merchant defined product code */ class Recurly_Transaction extends Recurly_Resource { - /** - * Get Tranasction by uuid - * - * @param string $uuid - * @param Recurly_Client $client optional - * @return Recurly_Transaction - */ + /** + * Get Transaction by uuid + * + * @param string $uuid + * @param Recurly_Client $client optional + * @return object Recurly_Transaction + * @throws Recurly_Error + */ public static function get($uuid, $client = null) { return Recurly_Base::_get(Recurly_Transaction::uriForTransaction($uuid), $client); } + /** + * @throws Recurly_Error + */ public function create() { $this->_save(Recurly_Client::POST, Recurly_Client::PATH_TRANSACTIONS); } /** * Refund a previous, successful transaction + * + * @param int $amountInCents + * @throws Recurly_Error */ public function refund($amountInCents = null) { $uri = $this->uri(); @@ -65,12 +71,18 @@ public function refund($amountInCents = null) { /** * Attempt a void, otherwise refund + * + * @throws Recurly_Error */ public function void() { trigger_error('Deprecated method: void(). Use refund() instead.', E_USER_NOTICE); $this->refund(); } + /** + * @return null|string + * @throws Recurly_Error + */ protected function uri() { if (!empty($this->_href)) return $this->getHref(); diff --git a/lib/recurly/usage.php b/lib/recurly/usage.php index 35c20188..5e2e4016 100644 --- a/lib/recurly/usage.php +++ b/lib/recurly/usage.php @@ -26,14 +26,28 @@ public static function build($subUuid, $addOnCode, $client = null) { return $usage; } + /** + * @throws Recurly_Error + */ public function create() { $this->_save(Recurly_Client::POST, Recurly_Usage::uriForUsages($this->subUuid, $this->addOnCode)); } + /** + * @throws Recurly_Error + */ public function update() { return $this->_save(Recurly_Client::PUT, $this->uri()); } + /** + * @param $subUuid + * @param $addOnCode + * @param $usageId + * @param Recurly_Client $client + * @return object + * @throws Recurly_Error + */ public static function get($subUuid, $addOnCode, $usageId, $client = null) { return Recurly_Base::_get(self::uriForUsage($subUuid, $addOnCode, $usageId), $client); }