Result.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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'));
  15. return $subscription;
  16. }
  17. function customer()
  18. {
  19. $customer = $this->_get('customer', 'ChargeBee_Customer',
  20. array('billing_address' => 'ChargeBee_CustomerBillingAddress', 'contacts' => 'ChargeBee_CustomerContact', 'payment_method' => 'ChargeBee_CustomerPaymentMethod'));
  21. return $customer;
  22. }
  23. function card()
  24. {
  25. $card = $this->_get('card', 'ChargeBee_Card');
  26. return $card;
  27. }
  28. function invoice()
  29. {
  30. $invoice = $this->_get('invoice', 'ChargeBee_Invoice',
  31. array('line_items' => 'ChargeBee_InvoiceLineItem', 'discounts' => 'ChargeBee_InvoiceDiscount', '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'));
  32. return $invoice;
  33. }
  34. function creditNote()
  35. {
  36. $credit_note = $this->_get('credit_note', 'ChargeBee_CreditNote',
  37. array('line_items' => 'ChargeBee_CreditNoteLineItem', 'discounts' => 'ChargeBee_CreditNoteDiscount', 'taxes' => 'ChargeBee_CreditNoteTax', 'line_item_taxes' => 'ChargeBee_CreditNoteLineItemTax', 'linked_refunds' => 'ChargeBee_CreditNoteLinkedRefund', 'allocations' => 'ChargeBee_CreditNoteAllocation'));
  38. return $credit_note;
  39. }
  40. function order()
  41. {
  42. $order = $this->_get('order', 'ChargeBee_Order');
  43. return $order;
  44. }
  45. function transaction()
  46. {
  47. $transaction = $this->_get('transaction', 'ChargeBee_Transaction',
  48. array('linked_invoices' => 'ChargeBee_TransactionLinkedInvoice', 'linked_credit_notes' => 'ChargeBee_TransactionLinkedCreditNote', 'linked_refunds' => 'ChargeBee_TransactionLinkedRefund'));
  49. return $transaction;
  50. }
  51. function hostedPage()
  52. {
  53. $hosted_page = $this->_get('hosted_page', 'ChargeBee_HostedPage');
  54. return $hosted_page;
  55. }
  56. function estimate()
  57. {
  58. $estimate = $this->_get('estimate', 'ChargeBee_Estimate', array(),
  59. array('subscription_estimate' => 'ChargeBee_SubscriptionEstimate', 'invoice_estimate' => 'ChargeBee_InvoiceEstimate', 'next_invoice_estimate' => 'ChargeBee_InvoiceEstimate', 'credit_note_estimates' => 'ChargeBee_CreditNoteEstimate'));
  60. $estimate->_initDependant($this->_response['estimate'], 'subscription_estimate',
  61. array());
  62. $estimate->_initDependant($this->_response['estimate'], 'invoice_estimate',
  63. array('line_items' => 'ChargeBee_InvoiceEstimateLineItem', 'discounts' => 'ChargeBee_InvoiceEstimateDiscount', 'taxes' => 'ChargeBee_InvoiceEstimateTax', 'line_item_taxes' => 'ChargeBee_InvoiceEstimateLineItemTax'));
  64. $estimate->_initDependant($this->_response['estimate'], 'next_invoice_estimate',
  65. array('line_items' => 'ChargeBee_InvoiceEstimateLineItem', 'discounts' => 'ChargeBee_InvoiceEstimateDiscount', 'taxes' => 'ChargeBee_InvoiceEstimateTax', 'line_item_taxes' => 'ChargeBee_InvoiceEstimateLineItemTax'));
  66. $estimate->_initDependantList($this->_response['estimate'], 'credit_note_estimates',
  67. array('line_items' => 'ChargeBee_CreditNoteEstimateLineItem', 'discounts' => 'ChargeBee_CreditNoteEstimateDiscount', 'taxes' => 'ChargeBee_CreditNoteEstimateTax', 'line_item_taxes' => 'ChargeBee_CreditNoteEstimateLineItemTax'));
  68. return $estimate;
  69. }
  70. function plan()
  71. {
  72. $plan = $this->_get('plan', 'ChargeBee_Plan');
  73. return $plan;
  74. }
  75. function addon()
  76. {
  77. $addon = $this->_get('addon', 'ChargeBee_Addon');
  78. return $addon;
  79. }
  80. function coupon()
  81. {
  82. $coupon = $this->_get('coupon', 'ChargeBee_Coupon');
  83. return $coupon;
  84. }
  85. function couponCode()
  86. {
  87. $coupon_code = $this->_get('coupon_code', 'ChargeBee_CouponCode');
  88. return $coupon_code;
  89. }
  90. function address()
  91. {
  92. $address = $this->_get('address', 'ChargeBee_Address');
  93. return $address;
  94. }
  95. function event()
  96. {
  97. $event = $this->_get('event', 'ChargeBee_Event',
  98. array('webhooks' => 'ChargeBee_EventWebhook'));
  99. return $event;
  100. }
  101. function comment()
  102. {
  103. $comment = $this->_get('comment', 'ChargeBee_Comment');
  104. return $comment;
  105. }
  106. function download()
  107. {
  108. $download = $this->_get('download', 'ChargeBee_Download');
  109. return $download;
  110. }
  111. function portalSession()
  112. {
  113. $portal_session = $this->_get('portal_session', 'ChargeBee_PortalSession',
  114. array('linked_customers' => 'ChargeBee_PortalSessionLinkedCustomer'));
  115. return $portal_session;
  116. }
  117. function creditNotes()
  118. {
  119. $credit_notes = $this->_getList('credit_notes', 'ChargeBee_CreditNote',
  120. array('line_items' => 'ChargeBee_CreditNoteLineItem', 'discounts' => 'ChargeBee_CreditNoteDiscount', 'taxes' => 'ChargeBee_CreditNoteTax', 'line_item_taxes' => 'ChargeBee_CreditNoteLineItemTax', 'linked_refunds' => 'ChargeBee_CreditNoteLinkedRefund', 'allocations' => 'ChargeBee_CreditNoteAllocation'));
  121. return $credit_notes;
  122. }
  123. private function _getList($type, $class, $subTypes = array(), $dependantTypes = array(), $dependantSubTypes = array())
  124. {
  125. if(!array_key_exists($type, $this->_response))
  126. {
  127. return null;
  128. }
  129. if(!array_key_exists($type, $this->_responseObj))
  130. {
  131. $setVal = array();
  132. foreach($this->_response[$type] as $stV)
  133. {
  134. $obj = new $class($stV, $subTypes, $dependantTypes);
  135. foreach($dependantSubTypes as $k => $v)
  136. {
  137. $obj->_initDependant($stV, $k, $v);
  138. }
  139. array_push($setVal, $obj);
  140. }
  141. $this->_responseObj[$type] = $setVal;
  142. }
  143. return $this->_responseObj[$type];
  144. }
  145. private function _get($type, $class, $subTypes = array(), $dependantTypes = array())
  146. {
  147. if(!array_key_exists($type, $this->_response))
  148. {
  149. return null;
  150. }
  151. if(!array_key_exists($type, $this->_responseObj))
  152. {
  153. $this->_responseObj[$type] = new $class($this->_response[$type], $subTypes, $dependantTypes);
  154. }
  155. return $this->_responseObj[$type];
  156. }
  157. }
  158. ?>