public function testRecurByDate()
 {
     $this->specify('sets the recurring fields', function () {
         $i = new \CoinSimple\Invoice();
         verify($i->data())->equals(array());
         $i->recurByDate(4);
         $data = $i->data();
         verify(array_key_exists('invoice_type', $data))->true();
         verify(array_key_exists('interval', $data))->true();
         verify($data['invoice_type'])->equals("date");
         verify($data['interval'])->equals(4);
     });
     $this->specify('converts param to int', function () {
         $i = new \CoinSimple\Invoice();
         verify($i->data())->equals(array());
         $i->recurByDate("4");
         $data = $i->data();
         verify(array_key_exists('invoice_type', $data))->true();
         verify(array_key_exists('interval', $data))->true();
         verify($data['invoice_type'])->equals("date");
         verify($data['interval'])->equals(4);
     });
 }
 /**
  * Translate WooCommerce order into coinsimple invoice and POST invoice to coinsimple.com.
  *
  * @access public
  * @todo determine how to handle order statuses in this function.
  * @param string $order_id rendezvous token that identifies a WooCommerce order.
  * @param $reply passed by reference, returned if successful.
  * @return boolean true if successful or false if unsuccessful.
  */
 public function post_invoice($order_id, &$reply)
 {
     $wc_order = new WC_Order($order_id);
     $invoice = new \CoinSimple\Invoice();
     $invoice->setName($wc_order->billing_first_name . ' ' . $wc_order->billing_last_name);
     $invoice->setEmail($wc_order->billing_email);
     $invoice->setCurrency(strtolower(get_woocommerce_currency()));
     // create line items
     $wc_items = $wc_order->get_items();
     foreach ($wc_items as $wc_item) {
         if (get_option('woocommerce_prices_include_tax') === 'yes') {
             $line_total = $wc_order->get_line_subtotal($wc_item, true, true);
         } else {
             $line_total = $wc_order->get_line_subtotal($wc_item, false, true);
         }
         $item = array("description" => $wc_item['name'], "quantity" => floatval($wc_item['qty']), "price" => round($line_total / $wc_item['qty'], 2));
         $invoice->addItem($item);
     }
     $invoice->setNotes($this->get_option("notes"));
     //tax
     if ($wc_order->get_total_tax() != 0 && get_option('woocommerce_prices_include_tax') !== 'yes') {
         $tax = 0;
         foreach ($wc_order->get_tax_totals() as $value) {
             $tax += $value->amount;
         }
         $tax = round($tax, 2);
         $invoice->addItem(array("description" => "Sales tax", "quantity" => 1, "price" => $tax));
     }
     // shipping
     if ($wc_order->get_total_shipping() != 0) {
         $shipping = $wc_order->get_total_shipping();
         if (get_option('woocommerce_prices_include_tax') === 'yes') {
             $shipping += $wc_order->get_shipping_tax();
         }
         $invoice->addItem(array("description" => "Shipping and handling", "quantity" => 1, "price" => round($shipping, 2)));
     }
     // coupens
     if ($wc_order->get_total_discount() != 0) {
         $invoice->addItem(array("description" => "Discounts", "quantity" => 1, "price" => -round($wc_order->get_total_discount(), 2)));
     }
     // settings part
     $invoice->setCallbackUrl(add_query_arg('wc-api', 'wc_coinsimple', home_url('/')));
     $invoice->setCustom(array("order_id" => $wc_order->id, "order_key" => $wc_order->order_key));
     if ($this->get_option("redirect_url") != "") {
         $invoice->setRedirectUrl($this->get_option("redirect_url"));
     }
     $business = new \CoinSimple\Business($this->get_option("business_id"), $this->get_option('api_key'));
     $res = $business->sendInvoice($invoice);
     if ($res->status == "ok") {
         $reply = $res;
         return true;
     } else {
         return false;
     }
 }