コード例 #1
0
ファイル: Orders.php プロジェクト: plescanicolai/billingSdk
 /**
  * @param Customer $customer
  * @return bool
  */
 public function createOrderForContract($customer)
 {
     //check if user have one order item
     $this->authService->logMessage('Start add order for contractId ' . $customer->getBillerfoxContractId());
     if (!$this->authService->accessToken) {
         $this->authService->setConfigDefault()->auth();
     }
     if (($orders = $this->getOrdersForOneContract($customer->getBillerfoxContractId(), true)) && (int) $orders['count'] != 0) {
         if (isset($orders['items'])) {
             foreach ($orders['items'] as $order) {
                 if (isset($order['order_items']) && count($order['order_items']) > 0) {
                     if (isset($order['order_items'][0]['id']) && ($orderItemId = $order['order_items'][0]['id'])) {
                         $options['form_params'] = ['access_token' => $this->authService->accessToken];
                         $response = $this->authService->getClient()->delete(Billing::UPDATE_ORDERS_PATH . Billing::API_DELIMITER . $order['id'] . Billing::UPDATE_ITEMS_PATH . Billing::API_DELIMITER . $orderItemId, $this->authService->getConfig() + $options);
                     }
                 }
             }
         }
     }
     $options['form_params'] = $this->prepareCustomerDataForOrder($customer) + ['access_token' => $this->authService->accessToken];
     $order = $this->authService->getClient()->post(Billing::CONTRACT_PATH . Billing::API_DELIMITER . $customer->getBillerfoxContractId() . Billing::ADD_ORDERS_PATH, $this->authService->getConfig() + $options);
     if ($order->getStatusCode() == 201) {
         $this->authService->initLastLogs();
         $this->authService->logMessage('Customer was created successfully. Order Id: ' . $order->getHeader('resource_id')[0], null, null, '', false, true);
         return [];
     } else {
         $orderResponseContent = json_decode($order->getBody()->getContents());
         $this->authService->logMessage('Contract Id was not returned and user was not created: ', $customer, '', '', false, true);
         $this->authService->setLastLogs($order);
     }
     return ['Create order error: ' . $orderResponseContent];
 }
コード例 #2
0
 /**
  * @param int $contractId
  * @return bool
  */
 public function deleteContract($contractId)
 {
     if (!$this->authService->accessToken) {
         $this->authService->setConfigDefault()->auth();
     }
     $options = ['form_params' => ['access_token' => $this->authService->accessToken]];
     $response = $this->authService->getClient()->delete(Billing::CONTRACT_PATH . Billing::API_DELIMITER . $contractId, $this->authService->getConfig() + $options);
     if ($response->getStatusCode() === 204) {
         $this->authService->initLastLogs();
         return true;
     } else {
         $this->authService->setLastLogs($response);
         return false;
     }
 }