Result.php 7.3 KB

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