Transactions.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. namespace OntraportAPI;
  3. /**
  4. * Class Transactions
  5. *
  6. * @author ONTRAPORT
  7. *
  8. * @package OntraportAPI
  9. */
  10. class Transactions extends BaseApi
  11. {
  12. /**
  13. * $var string endpoint for single transaction
  14. */
  15. protected $_endpoint = "Transaction";
  16. /**
  17. * $var string endpoint for plural transactions
  18. */
  19. protected $_endpointPlural = "Transactions";
  20. /**
  21. * @param Ontraport $client
  22. */
  23. public function __construct(Ontraport $client)
  24. {
  25. parent::__construct($client);
  26. }
  27. // Transaction-specific function endpoints
  28. const CONVERT_COLLECTIONS = "convertToCollections";
  29. const CONVERT_DECLINE = "convertToDecline";
  30. const MARK_PAID = "markPaid";
  31. const ORDER = "order";
  32. const PROCESS_MANUAL = "processManual";
  33. const REFUND = "refund";
  34. const RERUN = "rerun";
  35. const RERUN_COMMISSION = "rerunCommission";
  36. const RESEND_INVOICE = "resendInvoice";
  37. const VOID = "void";
  38. const WRITE_OFF = "writeOff";
  39. /**
  40. * @TODO: This is a placeholder, API needs to be changed to follow one standard for naming endpoints
  41. */
  42. private $_mainTransactionEndpoint = "transaction";
  43. /**
  44. * @brief Retrieve a single specified transaction
  45. *
  46. * @param mixed[] $requestParams The parameters to submit with GET request.
  47. * Possible array keys: "id" (required)
  48. *
  49. * @return string JSON formatted HTTP response
  50. */
  51. public function retrieveSingle($requestParams)
  52. {
  53. return parent::_retrieveSingle($requestParams);
  54. }
  55. /**
  56. * @brief Retrieve multiple transactions according to specific criteria, handle pagination
  57. *
  58. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional but if "ids"
  59. * are not specified, all will be selected.
  60. * Possible array keys: "ids","start","range","sort","sortDir","condition","search",
  61. * "searchNotes","group_ids","performAll","externs","listFields"
  62. *
  63. * @return string JSON formatted array of response data: each page of data will be an element in that array.
  64. */
  65. public function retrieveMultiplePaginated($requestParams)
  66. {
  67. return parent::_retrieveMultiplePaginated($requestParams);
  68. }
  69. /**
  70. * @brief Retrieve multiple transactions according to specific criteria
  71. *
  72. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional but if "ids"
  73. * are not specified, all will be selected.
  74. * Possible array keys: "ids","start","range","sort","sortDir","condition","search",
  75. * "searchNotes","group_ids","performAll","externs","listFields"
  76. *
  77. * @return string JSON formatted HTTP response
  78. */
  79. public function retrieveMultiple($requestParams)
  80. {
  81. return parent::_retrieveMultiple($requestParams);
  82. }
  83. /**
  84. * @brief Retrieve information (such as number of transactions) about transaction collection
  85. *
  86. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional.
  87. * Possible array keys: "condition","search","searchNotes","group_ids","performAll"
  88. *
  89. * @return string JSON formatted HTTP response
  90. */
  91. public function retrieveCollectionInfo($requestParams)
  92. {
  93. return parent::_retrieveCollectionInfo($requestParams);
  94. }
  95. /**
  96. * @brief Retrieve meta for a transaction object
  97. *
  98. * @return string JSON formatted meta for transaction object
  99. */
  100. public function retrieveMeta()
  101. {
  102. return parent::_retrieveMeta();
  103. }
  104. /**
  105. * @brief Convert the status of one or more transactions to collections
  106. *
  107. * @param mixed[] $requestParams Array of parameters to submit with PUT request.
  108. * Possible array keys: "id" (required)
  109. *
  110. * @return string JSON formatted HTTP response
  111. */
  112. public function convertToCollections($requestParams)
  113. {
  114. $requiredParams = array("id");
  115. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_FORM);
  116. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::CONVERT_COLLECTIONS, "put", $requiredParams, $options);
  117. }
  118. /**
  119. * @brief Convert the status of one or more transactions to declined
  120. *
  121. * @param mixed[] $requestParams Array of parameters to submit with PUT request.
  122. * Possible array keys: "id" (required)
  123. *
  124. * @return string JSON formatted HTTP response
  125. */
  126. public function convertToDeclined($requestParams)
  127. {
  128. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_FORM);
  129. $requiredParams = array("id");
  130. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::CONVERT_DECLINE, "put", $requiredParams, $options);
  131. }
  132. /**
  133. * @brief Mark a transaction as paid
  134. *
  135. * @param mixed[] $requestParams Array of parameters to submit with PUT request.
  136. * Possible array keys: "id" (required)
  137. *
  138. * @return string JSON formatted HTTP response
  139. */
  140. public function markAsPaid($requestParams)
  141. {
  142. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_FORM);
  143. $requiredParams = array("id");
  144. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::MARK_PAID, "put", $requiredParams, $options);
  145. }
  146. /**
  147. * @brief Retrieve information about an order
  148. *
  149. * @param mixed[] $requestParams Array of parameters to submit with GET request.
  150. * Possible array keys: "id" (required)
  151. *
  152. * @return string JSON formatted HTTP response
  153. */
  154. public function retrieveOrder($requestParams)
  155. {
  156. $requiredParams = array("id");
  157. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::ORDER, "get", $requiredParams, $options = NULL);
  158. }
  159. /**
  160. * @brief Update order information
  161. *
  162. * @param mixed[] $requestParams Array of parameters to submit with GET request.
  163. * Possible array keys: "id" (required)
  164. *
  165. * @return string JSON formatted HTTP response
  166. */
  167. public function updateOrder($requestParams)
  168. {
  169. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  170. $requiredParams = array("offer");
  171. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::ORDER, "put", $requiredParams, $options);
  172. }
  173. /**
  174. * @brief Create a transaction for a contact
  175. *
  176. * @param mixed[] $requestParams Array of parameters to submit with POST request.
  177. * Possible array keys: "contact_id" (required),"chargeNow" (required),"trans_date",
  178. * "invoice_template" (required),"gateway_id (required),"offer" (required),
  179. * "billing_address","payer"
  180. *
  181. * @return string JSON formatted HTTP response
  182. */
  183. public function processManual($requestParams)
  184. {
  185. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  186. $requiredParams = array(
  187. "contact_id",
  188. "chargeNow",
  189. "offer"
  190. );
  191. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::PROCESS_MANUAL, "post", $requiredParams, $options);
  192. }
  193. /**
  194. * @brief Refund one or more transactions
  195. *
  196. * @param mixed[] $requestParams Array of parameters to submit with PUT request.
  197. * Possible array keys: "objectID" (required),"ids","condition","start","range","group_ids",
  198. * "performAll","search","searchNotes"
  199. *
  200. * @return string JSON formatted response
  201. */
  202. public function refund($requestParams)
  203. {
  204. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  205. $requiredParams = array("objectID");
  206. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::REFUND, "put", $requiredParams, $options);
  207. }
  208. /**
  209. * @brief Rerun a single transaction or a group of transactions in collections
  210. *
  211. * @param mixed[] $requestParams Array of parameters to submit with POST request.
  212. * Possible array keys: "objectID" (required),"ids","condition","start","range","group_ids",
  213. * "performAll","search","searchNotes"
  214. *
  215. * @return string JSON formatted response
  216. */
  217. public function rerun($requestParams)
  218. {
  219. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  220. $requiredParams = array("objectID");
  221. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::RERUN, "post", $requiredParams, $options);
  222. }
  223. /**
  224. * @brief Rerun a partner commission
  225. *
  226. * @param mixed[] $requestParams Array of parameters to submit with PUT request.
  227. * Possible array keys: "objectID" (required),"ids","condition","start","range","group_ids",
  228. * "performAll","search","searchNotes"
  229. *
  230. * @return string JSON formatted response
  231. */
  232. public function rerunCommission($requestParams)
  233. {
  234. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  235. $requiredParams = array("objectID");
  236. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::RERUN_COMMISSION, "put", $requiredParams, $options);
  237. }
  238. /**
  239. * @brief Resend a transaction invoice
  240. *
  241. * @param mixed[] $requestParams Array of parameters to submit with POST request.
  242. * Possible array keys: "objectID" (required),"ids","condition","start","range","group_ids",
  243. * "performAll","search","searchNotes"
  244. *
  245. * @return string JSON formatted response
  246. */
  247. public function resendInvoice($requestParams)
  248. {
  249. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  250. $requiredParams = array("objectID");
  251. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::RESEND_INVOICE, "post", $requiredParams, $options);
  252. }
  253. /**
  254. * @brief Void one or more transactions
  255. *
  256. * @param mixed[] $requestParams Array of parameters to submit with PUT request.
  257. * Possible array keys: "objectID" (required),"ids","condition","start","range","group_ids",
  258. * "performAll","search","searchNotes"
  259. *
  260. * @return string JSON formatted response
  261. */
  262. public function void($requestParams)
  263. {
  264. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  265. $requiredParams = array("objectID");
  266. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::VOID, "put", $requiredParams, $options);
  267. }
  268. /**
  269. * @brief Write off one or more transactions
  270. *
  271. * @param mixed[] $requestParams Array of parameters to submit with PUT request.
  272. * Possible array keys: "objectID" (required),"ids","condition","start","range","group_ids",
  273. * "performAll","search","searchNotes"
  274. *
  275. * @return string JSON formatted response
  276. */
  277. public function writeOff($requestParams)
  278. {
  279. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  280. $requiredParams = array("objectID");
  281. return $this->client->request($requestParams, $this->_mainTransactionEndpoint . "/" . self::WRITE_OFF, "put", $requiredParams, $options);
  282. }
  283. }