Result.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. return $this->_get('subscription', 'ChargeBee_Subscription',
  14. array('addons' => 'ChargeBee_SubscriptionAddon', 'coupons' => 'ChargeBee_SubscriptionCoupon', 'shipping_address' => 'ChargeBee_SubscriptionShippingAddress'));
  15. }
  16. function customer()
  17. {
  18. return $this->_get('customer', 'ChargeBee_Customer',
  19. array('billing_address' => 'ChargeBee_CustomerBillingAddress', 'payment_method' => 'ChargeBee_CustomerPaymentMethod'));
  20. }
  21. function card()
  22. {
  23. return $this->_get('card', 'ChargeBee_Card');
  24. }
  25. function invoice()
  26. {
  27. return $this->_get('invoice', 'ChargeBee_Invoice',
  28. array('line_items' => 'ChargeBee_InvoiceLineItem', 'discounts' => 'ChargeBee_InvoiceDiscount', 'taxes' => 'ChargeBee_InvoiceTax', 'invoice_transactions' => 'ChargeBee_InvoiceLinkedTransaction', 'orders' => 'ChargeBee_InvoiceLinkedOrder', 'invoice_notes' => 'ChargeBee_InvoiceNote', 'shipping_address' => 'ChargeBee_InvoiceShippingAddress', 'billing_address' => 'ChargeBee_InvoiceBillingAddress'));
  29. }
  30. function order()
  31. {
  32. return $this->_get('order', 'ChargeBee_Order');
  33. }
  34. function transaction()
  35. {
  36. return $this->_get('transaction', 'ChargeBee_Transaction',
  37. array('invoice_transactions' => 'ChargeBee_TransactionLinkedInvoice'));
  38. }
  39. function hostedPage()
  40. {
  41. return $this->_get('hosted_page', 'ChargeBee_HostedPage');
  42. }
  43. function estimate()
  44. {
  45. return $this->_get('estimate', 'ChargeBee_Estimate',
  46. array('line_items' => 'ChargeBee_EstimateLineItem', 'discounts' => 'ChargeBee_EstimateDiscount', 'taxes' => 'ChargeBee_EstimateTax'));
  47. }
  48. function plan()
  49. {
  50. return $this->_get('plan', 'ChargeBee_Plan');
  51. }
  52. function addon()
  53. {
  54. return $this->_get('addon', 'ChargeBee_Addon');
  55. }
  56. function coupon()
  57. {
  58. return $this->_get('coupon', 'ChargeBee_Coupon');
  59. }
  60. function couponCode()
  61. {
  62. return $this->_get('coupon_code', 'ChargeBee_CouponCode');
  63. }
  64. function address()
  65. {
  66. return $this->_get('address', 'ChargeBee_Address');
  67. }
  68. function event()
  69. {
  70. return $this->_get('event', 'ChargeBee_Event',
  71. array('webhooks' => 'ChargeBee_EventWebhook'));
  72. }
  73. function comment()
  74. {
  75. return $this->_get('comment', 'ChargeBee_Comment');
  76. }
  77. function download()
  78. {
  79. return $this->_get('download', 'ChargeBee_Download');
  80. }
  81. function portalSession()
  82. {
  83. return $this->_get('portal_session', 'ChargeBee_PortalSession',
  84. array('linked_customers' => 'ChargeBee_PortalSessionLinkedCustomer'));
  85. }
  86. private function _get($type, $class, $subTypes = array())
  87. {
  88. if(!array_key_exists($type, $this->_response))
  89. {
  90. return null;
  91. }
  92. if(!array_key_exists($type, $this->_responseObj))
  93. {
  94. $this->_responseObj[$type] = new $class($this->_response[$type], $subTypes);
  95. }
  96. return $this->_responseObj[$type];
  97. }
  98. }
  99. ?>