示例#1
0
 /**
  * Prepares an Invoice to send to BitPay
  *
  * @param array $order_info OpenCart checkout order
  * @return Invoice
  */
 private function prepareInvoice($order_info = array())
 {
     $invoice = new \Bitpay\Invoice();
     if (empty($order_info['order_id'])) {
         $this->log('error', 'Cannot prepare invoice without `order_id`');
         throw Exception('Cannot prepare invoice without `order_id`');
     }
     $this->log('info', sprintf('Preparing Invoice for Order %s', (string) $order_info['order_id']));
     $invoice->setOrderId((string) $order_info['order_id']);
     if (empty($order_info['currency_code'])) {
         $this->log('error', 'Cannot prepare invoice without `currency_code`');
         throw Exception('Cannot prepare invoice without `currency_code`');
     }
     $invoice->setCurrency(new \Bitpay\Currency($order_info['currency_code']));
     if (empty($order_info['total'])) {
         $this->log('error', 'Cannot prepare invoice without `total`');
         throw Exception('Cannot prepare invoice without `total`');
     }
     $invoice->setPrice((double) $order_info['total']);
     // Send Buyer Information?
     if ($this->setting('send_buyer_info')) {
         $buyer = new \Bitpay\Buyer();
         $buyer->setFirstName($order_info['firstname'])->setLastName($order_info['lastname'])->setEmail($order_info['email'])->setPhone($order_info['telephone'])->setAddress(array($order_info['payment_address_1'], $order_info['payment_address_2']))->setCity($order_info['payment_city'])->setState($order_info['payment_zone_code'])->setZip($order_info['payment_postcode'])->setCountry($order_info['payment_country']);
         $invoice->setBuyer($buyer);
     }
     $invoice->setFullNotifications(true);
     $return_url = $this->setting('return_url');
     if (empty($return_url)) {
         $return_url = $this->url->link('payment/bitpay/success', $this->config->get('config_secure'));
     }
     $notify_url = $this->setting('notify_url');
     if (empty($notify_url)) {
         $notify_url = $this->url->link('payment/bitpay/callback', $this->config->get('config_secure'));
     }
     $invoice->setRedirectUrl($return_url);
     $invoice->setNotificationUrl($notify_url);
     $invoice->setTransactionSpeed($this->setting('risk_speed'));
     return $invoice;
 }