Result.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. class ChargeBee_Result
  3. {
  4. private $_response;
  5. private $_responseObj;
  6. function __construct($_response)
  7. {
  8. $this->_response = $_response;
  9. $this->_responseObj = array();
  10. }
  11. function subscription()
  12. {
  13. $subscription = $this->_get('subscription', 'ChargeBee_Subscription',
  14. array('addons' => 'ChargeBee_SubscriptionAddon', 'coupons' => 'ChargeBee_SubscriptionCoupon', 'shipping_address' => 'ChargeBee_SubscriptionShippingAddress', 'referral_info' => 'ChargeBee_SubscriptionReferralInfo'));
  15. return $subscription;
  16. }
  17. function customer()
  18. {
  19. $customer = $this->_get('customer', 'ChargeBee_Customer',
  20. array('billing_address' => 'ChargeBee_CustomerBillingAddress', 'referral_urls' => 'ChargeBee_CustomerReferralUrl', 'contacts' => 'ChargeBee_CustomerContact', 'payment_method' => 'ChargeBee_CustomerPaymentMethod', 'balances' => 'ChargeBee_CustomerBalance'));
  21. return $customer;
  22. }
  23. function contact()
  24. {
  25. $contact = $this->_get('contact', 'ChargeBee_Contact');
  26. return $contact;
  27. }
  28. function paymentSource()
  29. {
  30. $payment_source = $this->_get('payment_source', 'ChargeBee_PaymentSource',
  31. array('card' => 'ChargeBee_PaymentSourceCard', 'bank_account' => 'ChargeBee_PaymentSourceBankAccount', 'amazon_payment' => 'ChargeBee_PaymentSourceAmazonPayment', 'paypal' => 'ChargeBee_PaymentSourcePaypal'));
  32. return $payment_source;
  33. }
  34. function thirdPartyPaymentMethod()
  35. {
  36. $third_party_payment_method = $this->_get('third_party_payment_method', 'ChargeBee_ThirdPartyPaymentMethod');
  37. return $third_party_payment_method;
  38. }
  39. function virtualBankAccount()
  40. {
  41. $virtual_bank_account = $this->_get('virtual_bank_account', 'ChargeBee_VirtualBankAccount');
  42. return $virtual_bank_account;
  43. }
  44. function card()
  45. {
  46. $card = $this->_get('card', 'ChargeBee_Card');
  47. return $card;
  48. }
  49. function promotionalCredit()
  50. {
  51. $promotional_credit = $this->_get('promotional_credit', 'ChargeBee_PromotionalCredit');
  52. return $promotional_credit;
  53. }
  54. function invoice()
  55. {
  56. $invoice = $this->_get('invoice', 'ChargeBee_Invoice',
  57. array('line_items' => 'ChargeBee_InvoiceLineItem', 'discounts' => 'ChargeBee_InvoiceDiscount', 'line_item_discounts' => 'ChargeBee_InvoiceLineItemDiscount', 'taxes' => 'ChargeBee_InvoiceTax', 'line_item_taxes' => 'ChargeBee_InvoiceLineItemTax', 'linked_payments' => 'ChargeBee_InvoiceLinkedPayment', 'applied_credits' => 'ChargeBee_InvoiceAppliedCredit', 'adjustment_credit_notes' => 'ChargeBee_InvoiceAdjustmentCreditNote', 'issued_credit_notes' => 'ChargeBee_InvoiceIssuedCreditNote', 'linked_orders' => 'ChargeBee_InvoiceLinkedOrder', 'notes' => 'ChargeBee_InvoiceNote', 'shipping_address' => 'ChargeBee_InvoiceShippingAddress', 'billing_address' => 'ChargeBee_InvoiceBillingAddress'));
  58. return $invoice;
  59. }
  60. function creditNote()
  61. {
  62. $credit_note = $this->_get('credit_note', 'ChargeBee_CreditNote',
  63. array('line_items' => 'ChargeBee_CreditNoteLineItem', 'discounts' => 'ChargeBee_CreditNoteDiscount', 'line_item_discounts' => 'ChargeBee_CreditNoteLineItemDiscount', 'taxes' => 'ChargeBee_CreditNoteTax', 'line_item_taxes' => 'ChargeBee_CreditNoteLineItemTax', 'linked_refunds' => 'ChargeBee_CreditNoteLinkedRefund', 'allocations' => 'ChargeBee_CreditNoteAllocation'));
  64. return $credit_note;
  65. }
  66. function unbilledCharge()
  67. {
  68. $unbilled_charge = $this->_get('unbilled_charge', 'ChargeBee_UnbilledCharge');
  69. return $unbilled_charge;
  70. }
  71. function order()
  72. {
  73. $order = $this->_get('order', 'ChargeBee_Order');
  74. return $order;
  75. }
  76. function transaction()
  77. {
  78. $transaction = $this->_get('transaction', 'ChargeBee_Transaction',
  79. array('linked_invoices' => 'ChargeBee_TransactionLinkedInvoice', 'linked_credit_notes' => 'ChargeBee_TransactionLinkedCreditNote', 'linked_refunds' => 'ChargeBee_TransactionLinkedRefund'));
  80. return $transaction;
  81. }
  82. function hostedPage()
  83. {
  84. $hosted_page = $this->_get('hosted_page', 'ChargeBee_HostedPage');
  85. return $hosted_page;
  86. }
  87. function estimate()
  88. {
  89. $estimate = $this->_get('estimate', 'ChargeBee_Estimate', array(),
  90. array('subscription_estimate' => 'ChargeBee_SubscriptionEstimate', 'invoice_estimate' => 'ChargeBee_InvoiceEstimate', 'invoice_estimates' => 'ChargeBee_InvoiceEstimate', 'next_invoice_estimate' => 'ChargeBee_InvoiceEstimate', 'credit_note_estimates' => 'ChargeBee_CreditNoteEstimate', 'unbilled_charge_estimates' => 'ChargeBee_UnbilledCharge'));
  91. $estimate->_initDependant($this->_response['estimate'], 'subscription_estimate',
  92. array('shipping_address' => 'ChargeBee_SubscriptionEstimateShippingAddress'));
  93. $estimate->_initDependant($this->_response['estimate'], 'invoice_estimate',
  94. array('line_items' => 'ChargeBee_InvoiceEstimateLineItem', 'discounts' => 'ChargeBee_InvoiceEstimateDiscount', 'taxes' => 'ChargeBee_InvoiceEstimateTax', 'line_item_taxes' => 'ChargeBee_InvoiceEstimateLineItemTax', 'line_item_discounts' => 'ChargeBee_InvoiceEstimateLineItemDiscount'));
  95. $estimate->_initDependant($this->_response['estimate'], 'next_invoice_estimate',
  96. array('line_items' => 'ChargeBee_InvoiceEstimateLineItem', 'discounts' => 'ChargeBee_InvoiceEstimateDiscount', 'taxes' => 'ChargeBee_InvoiceEstimateTax', 'line_item_taxes' => 'ChargeBee_InvoiceEstimateLineItemTax', 'line_item_discounts' => 'ChargeBee_InvoiceEstimateLineItemDiscount'));
  97. $estimate->_initDependantList($this->_response['estimate'], 'invoice_estimates',
  98. array('line_items' => 'ChargeBee_InvoiceEstimateLineItem', 'discounts' => 'ChargeBee_InvoiceEstimateDiscount', 'taxes' => 'ChargeBee_InvoiceEstimateTax', 'line_item_taxes' => 'ChargeBee_InvoiceEstimateLineItemTax', 'line_item_discounts' => 'ChargeBee_InvoiceEstimateLineItemDiscount'));
  99. $estimate->_initDependantList($this->_response['estimate'], 'credit_note_estimates',
  100. array('line_items' => 'ChargeBee_CreditNoteEstimateLineItem', 'discounts' => 'ChargeBee_CreditNoteEstimateDiscount', 'taxes' => 'ChargeBee_CreditNoteEstimateTax', 'line_item_taxes' => 'ChargeBee_CreditNoteEstimateLineItemTax', 'line_item_discounts' => 'ChargeBee_CreditNoteEstimateLineItemDiscount'));
  101. $estimate->_initDependantList($this->_response['estimate'], 'unbilled_charge_estimates',
  102. array());
  103. return $estimate;
  104. }
  105. function plan()
  106. {
  107. $plan = $this->_get('plan', 'ChargeBee_Plan');
  108. return $plan;
  109. }
  110. function addon()
  111. {
  112. $addon = $this->_get('addon', 'ChargeBee_Addon');
  113. return $addon;
  114. }
  115. function coupon()
  116. {
  117. $coupon = $this->_get('coupon', 'ChargeBee_Coupon');
  118. return $coupon;
  119. }
  120. function couponSet()
  121. {
  122. $coupon_set = $this->_get('coupon_set', 'ChargeBee_CouponSet');
  123. return $coupon_set;
  124. }
  125. function couponCode()
  126. {
  127. $coupon_code = $this->_get('coupon_code', 'ChargeBee_CouponCode');
  128. return $coupon_code;
  129. }
  130. function address()
  131. {
  132. $address = $this->_get('address', 'ChargeBee_Address');
  133. return $address;
  134. }
  135. function event()
  136. {
  137. $event = $this->_get('event', 'ChargeBee_Event',
  138. array('webhooks' => 'ChargeBee_EventWebhook'));
  139. return $event;
  140. }
  141. function comment()
  142. {
  143. $comment = $this->_get('comment', 'ChargeBee_Comment');
  144. return $comment;
  145. }
  146. function download()
  147. {
  148. $download = $this->_get('download', 'ChargeBee_Download');
  149. return $download;
  150. }
  151. function portalSession()
  152. {
  153. $portal_session = $this->_get('portal_session', 'ChargeBee_PortalSession',
  154. array('linked_customers' => 'ChargeBee_PortalSessionLinkedCustomer'));
  155. return $portal_session;
  156. }
  157. function siteMigrationDetail()
  158. {
  159. $site_migration_detail = $this->_get('site_migration_detail', 'ChargeBee_SiteMigrationDetail');
  160. return $site_migration_detail;
  161. }
  162. function resourceMigration()
  163. {
  164. $resource_migration = $this->_get('resource_migration', 'ChargeBee_ResourceMigration');
  165. return $resource_migration;
  166. }
  167. function timeMachine()
  168. {
  169. $time_machine = $this->_get('time_machine', 'ChargeBee_TimeMachine');
  170. return $time_machine;
  171. }
  172. function export()
  173. {
  174. $export = $this->_get('export', 'ChargeBee_Export',
  175. array('download' => 'ChargeBee_ExportDownload'));
  176. return $export;
  177. }
  178. function unbilledCharges()
  179. {
  180. $unbilled_charges = $this->_getList('unbilled_charges', 'ChargeBee_UnbilledCharge',
  181. array());
  182. return $unbilled_charges;
  183. }
  184. function creditNotes()
  185. {
  186. $credit_notes = $this->_getList('credit_notes', 'ChargeBee_CreditNote',
  187. array('line_items' => 'ChargeBee_CreditNoteLineItem', 'discounts' => 'ChargeBee_CreditNoteDiscount', 'line_item_discounts' => 'ChargeBee_CreditNoteLineItemDiscount', 'taxes' => 'ChargeBee_CreditNoteTax', 'line_item_taxes' => 'ChargeBee_CreditNoteLineItemTax', 'linked_refunds' => 'ChargeBee_CreditNoteLinkedRefund', 'allocations' => 'ChargeBee_CreditNoteAllocation'));
  188. return $credit_notes;
  189. }
  190. function invoices()
  191. {
  192. $invoices = $this->_getList('invoices', 'ChargeBee_Invoice',
  193. array('line_items' => 'ChargeBee_InvoiceLineItem', 'discounts' => 'ChargeBee_InvoiceDiscount', 'line_item_discounts' => 'ChargeBee_InvoiceLineItemDiscount', 'taxes' => 'ChargeBee_InvoiceTax', 'line_item_taxes' => 'ChargeBee_InvoiceLineItemTax', 'linked_payments' => 'ChargeBee_InvoiceLinkedPayment', 'applied_credits' => 'ChargeBee_InvoiceAppliedCredit', 'adjustment_credit_notes' => 'ChargeBee_InvoiceAdjustmentCreditNote', 'issued_credit_notes' => 'ChargeBee_InvoiceIssuedCreditNote', 'linked_orders' => 'ChargeBee_InvoiceLinkedOrder', 'notes' => 'ChargeBee_InvoiceNote', 'shipping_address' => 'ChargeBee_InvoiceShippingAddress', 'billing_address' => 'ChargeBee_InvoiceBillingAddress'));
  194. return $invoices;
  195. }
  196. public function toJson() {
  197. return json_encode($this->_response);
  198. }
  199. private function _getList($type, $class, $subTypes = array(), $dependantTypes = array(), $dependantSubTypes = array())
  200. {
  201. if(!array_key_exists($type, $this->_response))
  202. {
  203. return null;
  204. }
  205. if(!array_key_exists($type, $this->_responseObj))
  206. {
  207. $setVal = array();
  208. foreach($this->_response[$type] as $stV)
  209. {
  210. $obj = new $class($stV, $subTypes, $dependantTypes);
  211. foreach($dependantSubTypes as $k => $v)
  212. {
  213. $obj->_initDependant($stV, $k, $v);
  214. }
  215. array_push($setVal, $obj);
  216. }
  217. $this->_responseObj[$type] = $setVal;
  218. }
  219. return $this->_responseObj[$type];
  220. }
  221. private function _get($type, $class, $subTypes = array(), $dependantTypes = array())
  222. {
  223. if(!array_key_exists($type, $this->_response))
  224. {
  225. return null;
  226. }
  227. if(!array_key_exists($type, $this->_responseObj))
  228. {
  229. $this->_responseObj[$type] = new $class($this->_response[$type], $subTypes, $dependantTypes);
  230. }
  231. return $this->_responseObj[$type];
  232. }
  233. }
  234. ?>