BillogramApiObjectsBillogramObject

Represents a billogram object on the Billogram service.

Defined (1)

The class is defined in the following location(s).

/Billogram/Api/Objects/BillogramObject.php  
  1. class BillogramObject extends SimpleObject 
  2. /** 
  3. * Makes a POST request to /billogram/{id}/command/{event}. 
  4. * @param $eventName 
  5. * @param null $eventData 
  6. * @return $this 
  7. */ 
  8. public function performEvent($eventName, $eventData = null) 
  9. $url = $this->url() . '/command/' . $eventName; 
  10. $response = $this->api->post($url, $eventData); 
  11. $this->data = (array) $response->data; 
  12.  
  13. return $this; 
  14.  
  15. /** 
  16. * Stores a manual payment for the billogram. 
  17. * @param $amount 
  18. * @return $this 
  19. */ 
  20. public function createPayment($amount) 
  21. return $this->performEvent('payment', array('amount' => $amount)); 
  22.  
  23. /** 
  24. * Creates a credit invoice for the specific amount. 
  25. * @param $amount 
  26. * @return $this 
  27. * @throws \Billogram\Api\Exceptions\InvalidFieldValueError 
  28. */ 
  29. public function creditAmount($amount) 
  30. if (!is_numeric($amount) || $amount <= 0) 
  31. throw new InvalidFieldValueError("'amount' must be a positive " . 
  32. "numeric value"); 
  33.  
  34. return $this->performEvent( 
  35. 'credit',  
  36. array( 
  37. 'mode' => 'amount',  
  38. 'amount' => $amount 
  39. ); 
  40.  
  41. /** 
  42. * Creates a credit invoice for the full total amount of the billogram. 
  43. * @return $this 
  44. */ 
  45. public function creditFull() 
  46. return $this->performEvent('credit', array('mode' => 'full')); 
  47.  
  48. /** 
  49. * Creates a credit invoice for the remaining amount of the billogram. 
  50. * @return $this 
  51. */ 
  52. public function creditRemaining() 
  53. return $this->performEvent('credit', array('mode' => 'remaining')); 
  54.  
  55. /** 
  56. * Writes a comment/message at the billogram. 
  57. * @param $message 
  58. * @return $this 
  59. */ 
  60. public function sendMessage($message) 
  61. return $this->performEvent('message', array('message' => $message)); 
  62.  
  63. /** 
  64. * Sends the billogram for collection. Requires a collectors-agreement. 
  65. * @return $this 
  66. */ 
  67. public function sendToCollector() 
  68. return $this->performEvent('collect'); 
  69.  
  70. /** 
  71. * Sends to billogram to factoring (sell the billogram). Requires a 
  72. * factoring-agreement. 
  73. * @return $this 
  74. */ 
  75. public function sendToFactoring() 
  76. return $this->performEvent('sell'); 
  77.  
  78. /** 
  79. * Manually send a reminder if the billogram is overdue. 
  80. * @param null $method 
  81. * @return $this 
  82. * @throws \Billogram\Api\Exceptions\InvalidFieldValueError 
  83. */ 
  84. public function sendReminder($method = null) 
  85. if ($method) { 
  86. if (!in_array($method, array('Email', 'Letter'))) 
  87. throw new InvalidFieldValueError("'method' must be either " . 
  88. "'Email' or 'Letter'"); 
  89.  
  90. return $this->performEvent('remind', array('method' => $method)); 
  91.  
  92. return $this->performEvent('remind'); 
  93.  
  94. /** 
  95. * Send an unsent billogram using the method of choice 
  96. * @param $method 
  97. * @return $this 
  98. * @throws \Billogram\Api\Exceptions\InvalidFieldValueError 
  99. */ 
  100. public function send($method) 
  101. if (!in_array($method, array('Email', 'Letter', 'Email+Letter'))) 
  102. throw new InvalidFieldValueError("'method' must be either " . 
  103. "'Email', 'Letter' or 'Email+Letter'"); 
  104.  
  105. return $this->performEvent('send', array('method' => $method)); 
  106.  
  107. /** 
  108. * Resend a billogram via Email or Letter. 
  109. * @param null $method 
  110. * @return $this 
  111. * @throws \Billogram\Api\Exceptions\InvalidFieldValueError 
  112. */ 
  113. public function resend($method = null) 
  114. if ($method) { 
  115. if (!in_array($method, array('Email', 'Letter'))) 
  116. throw new InvalidFieldValueError("'method' must be either " . 
  117. "'Email' or 'Letter'"); 
  118.  
  119. return $this->performEvent('resend', array('method' => $method)); 
  120.  
  121. return $this->performEvent('resend'); 
  122.  
  123. /** 
  124. * Returns the PDF-file content for a specific billogram, invoice 
  125. * or letter document. Will throw a ObjectNotFoundError with message 
  126. * 'Object not available yet' if the PDF has not yet been generated. 
  127. * @param null $letterId 
  128. * @param null $invoiceNo 
  129. * @return string 
  130. * @throws \Billogram\Api\Exceptions\ObjectNotFoundError 
  131. */ 
  132. public function getInvoicePdf($letterId = null, $invoiceNo = null) 
  133. $params = array(); 
  134. if ($letterId) 
  135. $params['letter_id'] = $letterId; 
  136. if ($invoiceNo) 
  137. $params['invoice_no'] = $invoiceNo; 
  138.  
  139. $response = $this->api->get( 
  140. $this->url() . '.pdf',  
  141. $params,  
  142. 'application/json' 
  143. ); 
  144.  
  145. return base64_decode($response->data->content); 
  146.  
  147. /** 
  148. * Returns the PDF-file content for the billogram's attachment. 
  149. * @return string 
  150. */ 
  151. public function getAttachmentPdf() 
  152. $response = $this->api->get( 
  153. $this->url() . '/attachment.pdf',  
  154. null,  
  155. 'application/json' 
  156. ); 
  157.  
  158. return base64_decode($response->data->content); 
  159.  
  160. /** 
  161. * Attach a PDF to the billogram. 
  162. * @param $filepath 
  163. * @return $this 
  164. */ 
  165. public function attachPdf($filepath) 
  166. $content = file_get_contents($filepath); 
  167. $filename = basename($filepath); 
  168.  
  169. return $this->performEvent('attach', array('filename' => $filename, 'content' => base64_encode($content)));