title: How to create a BillPayment through the IPP Service
body: <p>We use the IPP Services to push/fetch data in QuickBooks Online. We're having issues creating a <code>BillPayment</code>. There is no "Add a BillPayment" in the provided exemples (/docs/partner_platform/example_app_ipp_v3).</p>
  
  <p>We've managed to get all the variables right, excepted the <code>Line</code> object. It's a little confusing since there's a <code>Payment</code> object.</p>
  
  <p>How do you proceed? Is there an existing working/full exemple of this type of transactions?</p>
  
  <p>We tried the following code (copied the <code>Payment</code> exemple code) to add the <code>Line</code> object:</p>
  
  <pre><code>$Line = new QuickBooks_IPP_Object_Line();
  $Line-&gt;setAmount(10);
  
  $LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
  $LinkedTxn-&gt;setTxnId('{-84}'); //Is this the Bill Ref ID?
  $LinkedTxn-&gt;setTxnType('Bill');
  
  $Line-&gt;setLinkedTxn($LinkedTxn);
  
  $BillPaymentObject-&gt;addLine($Line);
  </code></pre>
  
  <p><code>Payment</code> object variables:</p>
  
  <ul>
  <li>docNumber</li>
  <li>txnDate</li>
  <li>vendorRef</li>
  <li>payType (value = CreditCardPayment)</li>
  <li>CreditCardPayment (credit card number?)</li>
  <li>totalAmt</li>
  </ul>
  
  <p>The generated error suggests that an Account should be provided. The documentation has <code>APAccountRef</code> and <code>CCAccountRef</code>, but we tried applying them and failed. The error doesn't provide the information about wether it's the <code>Line</code> object that's in an error state or the <code>Payment</code> object.</p>
  
  <p><code>6000: [A business validation error has occurred while processing your request, Business Validation Error: Vous devez sélectionner un compte pour cette opération.]</code> (You must select an account for this operation)</p>
  
  <p>Last request XML:</p>
  
  <p><code>&lt;billpayment xmlns="http://schema.intuit.com/finance/v3"&gt;
      &lt;docnumber&gt;11&lt;/docnumber&gt;
      &lt;txndate&gt;2014-06-14&lt;/txndate&gt;
      &lt;vendorref&gt;8&lt;/vendorref&gt;
      &lt;paytype&gt;CreditCardPayment=10&lt;/paytype&gt;
      &lt;creditcardpayment&gt;1111222233334444&lt;/creditcardpayment&gt;
      &lt;ccaccountref&gt;15&lt;/ccaccountref&gt;
      &lt;totalamt&gt;1.50&lt;/totalamt&gt;
      &lt;line xmlns="http://schema.intuit.com/finance/v3"&gt;
          &lt;amount&gt;10&lt;/amount&gt;
          &lt;linkedtxn xmlns="http://schema.intuit.com/finance/v3"&gt;
              &lt;txnid&gt;11&lt;/txnid&gt;
              &lt;txntype&gt;Bill&lt;/txntype&gt;
          &lt;/linkedtxn&gt;
      &lt;/line&gt;
  &lt;/billpayment&gt;</code></p>
  
  <p>Full PHP code exemple without the AUTH part (behold):</p>
  
  <pre><code>$str_service = 'QuickBooks_IPP_Service_'.$_REQUEST['type'];
  $str_object = 'QuickBooks_IPP_Object_'.$_REQUEST['type'];
  
  //Création d'un item
  $Service = new $str_service();
  $Object = new $str_object();
  
  $arr_excluded_key = array('token', 'type', 'arr_item', 'billAddrLine1', 'billAddrLine2', 'billAddrCity', 'billAddrCountrySubDivisionCode', 'billAddrPostalCode', 'primaryPhone', 'fax', 'mobile');
  //Boucle pour les set
  foreach($_REQUEST as $key =&gt; $value){
       if(!in_array($key, $arr_excluded_key)){
          $str_method = 'set'.ucfirst($key);
          $Object-&gt;$str_method($value);
      }
   }
  
   switch($_REQUEST['type']){
      case 'BillPayment':
          foreach($_REQUEST['arr_item'] as $item){
              $Line = new QuickBooks_IPP_Object_Line();
              $Line-&gt;setAmount(10); //Static for testing purposes
  
              // The line has a LinkedTxn node which links to the actual bill
              $LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
               $LinkedTxn-&gt;setTxnId('{-11}'); //Static for testing purposes
              $LinkedTxn-&gt;setTxnType('Bill');
  
              $Line-&gt;setLinkedTxn($LinkedTxn);
  
              $Object-&gt;addLine($Line);
          }
          break;
  }
  
  //Response
  #$Service-&gt;add($Context, $realm, $Object);
  #echo $Service-&gt;lastRequest($Context);exit;
  if ($resp = $Service-&gt;add($Context, $realm, $Object)){
      print($resp);
  }
  else{
      print($Service-&gt;lastError($Context));
  }
  </code></pre>
  
  <p>This is the query sent (it's the real URL, it should work for testing purposes): <code>http://dev.magikweb.ca/magik-net/quickbooks/save.php?token=aaabbbcccddd1234&amp;type=BillPayment&amp;docNumber=11&amp;txnDate=2014-06-14&amp;vendorRef=8&amp;payType=CreditCardPayment=10&amp;CreditCardPayment=1111222233334444&amp;CCAccountRef=15&amp;totalAmt=1.50&amp;arr_item[0][amount]=0.75&amp;arr_item[0][txnId]=11&amp;arr_item[0][amount]=0.75&amp;arr_item[0][txnId]=11</code></p>