• I am trying to use the API to generate an invoice on submissions of a gravity form.

    I have tried using your examples found here:
    https://wp-invoice.github.io/docs/api/

    I have created a test.php file and put it in my wordpress root and cut and past your create_invoice example. I have also added the following to the top of the file:

    
    define('WP_USE_THEMES', false);
    define("ABSPATH", dirname(__FILE__) . '/');
    define("WPINC", "/wp-includes");
    require('wp-blog-header.php');
    require( "wp-load.php" );
    

    When I run the file from a url (www.mysite.com/test.php), I do not get errors but I also do not create an invoice. What am I missing?

    -Craig

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter cravaus

    (@cravaus)

    Or perhaps there is a better way to generate an invoice on submit of my gravity form. Perhaps the API is not needed if I am within the same site. Are there already functions, hooks, filters, that I can use within the plug in to submit an invoice?

    Thread Starter cravaus

    (@cravaus)

    My solution given that I am trying to integrate with Gravity Forms and I am already within the server is to do this:

    
    <?php
    include ( "wp-load.php" );
      $args = array(
          'subject'     => 'Test API Invoice',
          'description' => 'Invoice descriptive information.',
          'type'        => 'invoice',
          'user_data'   => array(
              'user_email' => '[email protected]',
              'first_name' => 'Lary',
              'last_name'  => 'Test'
          ),
          'deposit'     => 15.99,
          'due_date'    => array(
              'month' => '09',
              'day'   => '10',
              'year'  => '2013'
          ),
          'currency'    => 'USD',
          'tax'         => 10.5,
          'tax_method'  => 'after_discount',
          'status'      => 'active',
          'discount'  => array(
              'name'   => 'Your Discount',
              'type'   => 'amount',
              'amount' => 1.20
          ),
          'items' => array(
              array(
                  'name' => 'Test item 1',
                  'description' => 'Item 1 description',
                  'quantity' => 2,
                  'price' => 2.65,
                  'tax_rate' => 1 //global 'tax' will be used in order to priority
              ),
              array(
                  'name' => 'Test item 2',
                  'description' => 'Item 2 description',
                  'quantity' => 4,
                  'price' => 3.85
              )
          ),
          'charges' => array(
              array(
                  'name' => 'Fee 1',
                  'amount' => 0.56
              ),
              array(
                  'name' => 'Fee 2',
                  'amount' => 0.99,
                  'tax' => 15 //global 'tax' will be used in order to priority
              )
          )
      );
      
    $WPI_XMLRPC_API = new WPI_XMLRPC_API(); 
    $new_invoice = $WPI_XMLRPC_API->create_invoice($args);
    

    It does the job and I can build a function to gather the form field data from my gravity form and replace the values with variables from the form and have an invoice created. Perfect.

    • This reply was modified 6 years, 8 months ago by cravaus.
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Generate invoice with API’ is closed to new replies.