From dab1e052dedff5243eadf9b5c8ff67fd7d04a633 Mon Sep 17 00:00:00 2001 From: Lei Pan Date: Tue, 5 Jan 2016 14:42:19 -0800 Subject: [PATCH] add support for object approval, http://developer.bill.com/api-documentation/api/approvals-workflow --- src/BillComApi/BillCom.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/BillComApi/BillCom.php b/src/BillComApi/BillCom.php index 809b42e..268d9c0 100644 --- a/src/BillComApi/BillCom.php +++ b/src/BillComApi/BillCom.php @@ -296,6 +296,42 @@ public function delete($obj_url, $obj_id) return $this->crud('Delete', $obj_url, array('id' => $obj_id)); } + /** + * Approve an object, can only be Bill or VendorCredit + * @param + * @param array data object data + * @return object result data + * @throws BillComException + */ + public function approve_object($data) + { + if ($data['entity'] != "Bill" || $data['entity'] != "VendorCredit") { + throw new BillcomException("Invalid entity type. Only Bill or VendorCredit is supported."); + } + + if (empty($this->session_id)) { + $this->login(); + } + + $result = $this->do_request( + $this->host . "Approve.json", + array( + 'devKey' => $this->dev_key, + 'sessionId' => $this->session_id, + 'data' => json_encode($data), + ) + ); + if ($result->succeeded()) { + return $result->get_data(); + } else { + throw new BillComException(sprintf( + "Error during Approve. data:\n%s\nresponse details:\n%s", + var_export($data, true), + var_export($result, true) + )); + } + } + /** * Pays a bill. * @param array data payment data