magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

invoice not found in admin panel after being created and getting the response back via rest api magento 2.0

Open neelimabenapally opened this issue 10 years ago • 2 comments

Below is the code to create invoice via rest api

   <?php
   $adminUrl='http://xxxxxx/index.php/rest/V1/integration/admin/token';
   $ch = curl_init();
   $data = array("username" => "xxxxx", "password" => "xxxxx");                                                                    
   $data_string = json_encode($data);                       
   $ch = curl_init($adminUrl); 
   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
   curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
   curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
      'Content-Type: application/json',                                                                                
       'Content-Length: ' . strlen($data_string))                                                                       
       );       
   $token = curl_exec($ch);
   $token=  json_decode($token); 
   $headers = array("Authorization: Bearer $token"); 
  $requestUrl='http://xxxxxx/index.php/rest/V1/invoices';
  $body=array("entity"=>array("baseCurrencyCode"=>"USD","baseDiscountAmount"=>                0,"baseGrandTotal"=> 119.93,
    "baseDiscountTaxCompensationAmount"=> 0,
    "baseShippingAmount"=> 15,
    "baseShippingDiscountTaxCompensationAmnt"=> "",
    "baseShippingInclTax"=> 15,
    "baseShippingTaxAmount"=> 0,
    "baseSubtotal"=> 104.93,
    "baseSubtotalInclTax"=> 104.93,
    "baseTaxAmount"=> 0,
    "baseTotalRefunded"=> 0,
    "baseToGlobalRate"=> 1,
    "baseToOrderRate"=> 1,
    "billingAddressId"=> 2,
    "canVoidFlag"=> 0,
    "createdAt"=> "2016-05-04 14:09:23",
    "discountAmount"=> 0,
    "discountDescription"=> null,
    "emailSent"=> 1,
    "entityId"=> 1,
    "globalCurrencyCode"=> "USD",
    "grandTotal"=> 119.93,
    "discountTaxCompensationAmount"=> 0,
    "incrementId"=> "000000001",
    "isUsedForRefund"=> 0,
    "orderCurrencyCode"=> "USD",
    "orderId"=> 1,
    "shippingAddressId"=> 0,
    "shippingAmount"=> 15,
    "shippingDiscountTaxCompensationAmount"=> 0,
    "shippingInclTax"=> 15,
    "shippingTaxAmount"=> 0,
    "state"=> "new",
    "storeCurrencyCode"=> "USD",
    "storeId"=> 1,
    "storeToBaseRate"=> 0,
    "storeToOrderRate"=> 0,
    "subtotal"=> 104.93,
    "subtotalInclTax"=> 104.93,
    "taxAmount"=> 0,
    "totalQty"=> 3,
    "transactionId"=> 000000001,
    "updatedAt"=> "2016-05-04 14:09:26",
    "items"=> array(

            array("additionalData"=> "",
            "baseCost"=> 9.99,
            "baseDiscountAmount"=> 0,
            "baseDiscountTaxCompensationAmount"=> 0,
            "basePrice"=> 9.99,
            "basePriceInclTax"=> 9.99,
            "baseRowTotal"=> 9.99,
            "baseRowTotalInclTax"=> 9.99,
            "baseTaxAmount"=> 0,
            "description"=> "",
            "discountAmount"=> 0,
            "entityId"=> 1,
            "discountTaxCompensationAmount"=> 0,
            "name"=> "xxxxx",
            "orderItemId"=> 1,
            "parentId"=> 1,
            "price"=> 9.99,
            "priceInclTax"=> 9.99,
            "productId"=> 1,
            "qty"=> 1,
            "rowTotal"=> 9.99,
            "rowTotalInclTax"=> 9.99,
            "sku"=> "xxxxx",
            "taxAmount"=> 0,
            "extensionAttributes"=>array()),


            array("additionalData"=> "",
            "baseCost"=> 69.95,
            "baseDiscountAmount"=> 0,
            "baseDiscountTaxCompensationAmount"=> 0,
            "basePrice"=> 69.95,
            "basePriceInclTax"=> 69.95,
            "baseRowTotal"=> 69.95,
            "baseRowTotalInclTax"=> 69.95,
            "baseTaxAmount"=> 0,
            "description"=> "",
            "discountAmount"=> 0,
            "entityId"=> 1,
            "discountTaxCompensationAmount"=> 0,
            "name"=> "xxxxx",
            "orderItemId"=> 2,
            "parentId"=> 1,
            "price"=> 69.95,
            "priceInclTax"=> 69.95,
            "productId"=> 54,
            "qty"=> 1,
            "rowTotal"=> 69.95,
            "rowTotalInclTax"=> 69.95,
            "sku"=> "xxxxx",
            "taxAmount"=> 0,
            "extensionAttributes"=>array()),


            array("additionalData"=> "",
            "baseCost"=> 24.99,
            "baseDiscountAmount"=> 0,
            "baseDiscountTaxCompensationAmount"=> 0,
            "basePrice"=> 24.99,
            "basePriceInclTax"=> 24.99,
            "baseRowTotal"=> 24.99,
            "baseRowTotalInclTax"=> 24.99,
            "baseTaxAmount"=> 0,
            "description"=> "",
            "discountAmount"=> 0,
            "entityId"=> 1,
            "discountTaxCompensationAmount"=> 0,
            "name"=> "xxxxx",
            "orderItemId"=> 3,
            "parentId"=> 1,
            "price"=> 24.99,
            "priceInclTax"=> 24.99,
            "productId"=> 55,
            "qty"=> 1,
            "rowTotal"=> 24.99,
            "sku"=> "xxxxxx",
            "taxAmount"=> 0,
            "extensionAttributes"=>array())),

    "comments"=>array(
        array("comment"=> "invoice created",
             "createdAt"=> "2016-05-04 14:09:23",
            "entityId"=> 1,
            "isCustomerNotified"=> 1,
            "isVisibleOnFront"=> 1,
            "parentId"=> 1,
            "extensionAttributes"=> array()),
    array("comment"=> "invoice created",
             "createdAt"=> "2016-05-04 14:09:23",
            "entityId"=> 1,
            "isCustomerNotified"=> 1,
            "isVisibleOnFront"=> 1,
            "parentId"=> 1,
            "extensionAttributes"=> array()),
    array("comment"=> "invoice created",
             "createdAt"=> "2016-05-04 14:09:23",
            "entityId"=> 1,
            "isCustomerNotified"=> 1,
            "isVisibleOnFront"=> 1,
            "parentId"=> 1,
            "extensionAttributes"=> array())),
    "extensionAttributes"=> array()));
     $body1=json_encode($body);
    $ch = curl_init();
    $ch = curl_init($requestUrl); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$body1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
    $result1 = curl_exec($ch);
    $result1=  json_decode($result1,true);
    print_r($result1);
   ?>

I got the response as:

{"base_currency_code":"USD","base_discount_amount":0,"base_grand_total":119.93,"base_discount_tax_compensation_amount":0,"base_shipping_amount":15,"base_shipping_discount_tax_compensation_amnt":0,"base_shipping_incl_tax":15,"base_shipping_tax_amount":0,"base_subtotal":104.93,"base_subtotal_incl_tax":104.93,"base_tax_amount":0,"base_total_refunded":0,"base_to_global_rate":1,"base_to_order_rate":1,"billing_address_id":2,"can_void_flag":0,"created_at":"2016-05-04 14:09:23","discount_amount":0,"email_sent":1,"entity_id":1,"global_currency_code":"USD","grand_total":119.93,"discount_tax_compensation_amount":0,"increment_id":"000000001","is_used_for_refund":0,"order_currency_code":"USD","order_id":1,"shipping_address_id":0,"shipping_amount":15,"shipping_discount_tax_compensation_amount":0,"shipping_incl_tax":15,"shipping_tax_amount":0,"state":0,"store_currency_code":"USD","store_id":1,"store_to_base_rate":0,"store_to_order_rate":0,"subtotal":104.93,"subtotal_incl_tax":104.93,"tax_amount":0,"total_qty":3,"transaction_id":"1","updated_at":"2016-05-12 09:19:27","items":[{"additional_data":"","base_cost":9.99,"base_discount_amount":0,"base_discount_tax_compensation_amount":0,"base_price":9.99,"base_price_incl_tax":9.99,"base_row_total":9.99,"base_row_total_incl_tax":9.99,"base_tax_amount":0,"description":"","discount_amount":0,"entity_id":1,"discount_tax_compensation_amount":0,"name":"xxx xxx","order_item_id":1,"parent_id":1,"price":9.99,"price_incl_tax":9.99,"product_id":1,"qty":1,"row_total":9.99,"row_total_incl_tax":9.99,"sku":"xxxxx","tax_amount":0,"extension_attributes":[]},{"additional_data":"","base_cost":69.95,"base_discount_amount":0,"base_discount_tax_compensation_amount":0,"base_price":69.95,"base_price_incl_tax":69.95,"base_row_total":69.95,"base_row_total_incl_tax":69.95,"base_tax_amount":0,"description":"","discount_amount":0,"entity_id":1,"discount_tax_compensation_amount":0,"name":"xxxx","order_item_id":2,"parent_id":1,"price":69.95,"price_incl_tax":69.95,"product_id":54,"qty":1,"row_total":69.95,"row_total_incl_tax":69.95,"sku":"xxxx","tax_amount":0,"extension_attributes":[]},{"additional_data":"","base_cost":24.99,"base_discount_amount":0,"base_discount_tax_compensation_amount":0,"base_price":24.99,"base_price_incl_tax":24.99,"base_row_total":24.99,"base_row_total_incl_tax":24.99,"base_tax_amount":0,"description":"","discount_amount":0,"entity_id":1,"discount_tax_compensation_amount":0,"name":xxxx","order_item_id":3,"parent_id":1,"price":24.99,"price_incl_tax":24.99,"product_id":55,"qty":1,"row_total":24.99,"sku":"xxxxx","tax_amount":0,"extension_attributes":[]}],"comments":[{"comment":"invoice created","created_at":"2016-05-04 14:09:23","entity_id":1,"is_customer_notified":1,"is_visible_on_front":1,"parent_id":1,"extension_attributes":[]},{"comment":"invoice created","created_at":"2016-05-04 14:09:23","entity_id":1,"is_customer_notified":1,"is_visible_on_front":1,"parent_id":1,"extension_attributes":[]},{"comment":"invoice created","created_at":"2016-05-04 14:09:23","entity_id":1,"is_customer_notified":1,"is_visible_on_front":1,"parent_id":1,"extension_attributes":[]}],"extension_attributes":[]}11

After getting this response there is no invoice found in the admin panel and the order status is still pending

neelimabenapally avatar May 12 '16 09:05 neelimabenapally

@neelimabenapally, thank you for reporting. Please fill description according to the template and specify full Magento version here.

andimov avatar Jun 23 '16 10:06 andimov

According to contributor guide, tickets without response for two weeks should be closed. Please feel free to reopen if it's needed.

palamar avatar Jul 07 '16 14:07 palamar