public static function chargeInvoiceArbitraryAmount($contactId, $invoiceId, $cardId, $amount, $merchantAccountId, $invoiceNotes = 'API Arbitrary Payment') { //Create a new order (InvoiceService.blankOrder... $dummyInvoiceId = Infusionsoft_InvoiceService::createBlankOrder($contactId, $invoiceNotes . " Invoice: " . $amount, date('Ymd\\TH:i:s')); try { //Add an order item that is the correct amount you want to charge... Infusionsoft_InvoiceService::addOrderItem($dummyInvoiceId, 0, 3, $amount, 1, $invoiceNotes . " order", ""); //Set orders custom field "_ChargeStatus" to "Pending" $invoice = new Infusionsoft_Invoice($dummyInvoiceId); $dummyOrder = new Infusionsoft_Job($invoice->JobId); $dummyOrder->OrderStatus = "Pending"; $dummyOrder->save(); //Try to charge the invoice $result = Infusionsoft_InvoiceService::chargeInvoice($dummyInvoiceId, $invoiceNotes . " payment", $cardId, $merchantAccountId, false); } catch (Exception $e) { Infusionsoft_InvoiceService::deleteInvoice($dummyInvoiceId); throw new Exception("Failed to charge partial payment. Infusionsoft says: " . $e->getMessage()); } //Update order status "_ChargeStatus" to "Failed", or "Succeeded" if ($result['Successful']) { //add a credit to the order Infusionsoft_InvoiceService::addManualPayment($invoiceId, $amount, date('Ymd\\TH:i:s'), "Credit Card", $invoiceNotes . " partial payment", false); $dummyOrder->OrderStatus = "Successful"; $dummyOrder->save(); } else { //erase the invoice Infusionsoft_InvoiceService::deleteInvoice($dummyInvoiceId); } return $result; //Update order status to "Applied" }
public function save($app = null) { if ($this->Id == '') { $invoices = Infusionsoft_DataService::query(new Infusionsoft_Invoice(), array('JobId' => $this->OrderId), 1000, 0, false, $app); if (count($invoices) == 0) { throw new Infusionsoft_Exception("Could not get invoice for order: " . $this->OrderId . " while creating adding an order item."); } /** @var Infusionsoft_Invoice $invoice */ $invoice = array_shift($invoices); $result = Infusionsoft_InvoiceService::addOrderItem($invoice->Id, $this->ProductId, $this->ItemType, $this->PPU, $this->Qty, $this->ItemDescription, $this->Notes, $app); if (!$result) { throw new Infusionsoft_Exception("Couldn't save orderitem: " . json_encode($this->toArray())); } //Infusionsoft doesn't always use consecutive Ids, but it is very very very rare that the id won't be consecutive if a new record is inserted very quickly after the previous, so even though this isn't ideal, it's what we are doing. $newestOrderItems = Infusionsoft_DataService::queryWithOrderBy(new Infusionsoft_OrderItem(), array('OrderId' => $this->OrderId), 'Id', false, 1); $newestOrderItem = array_shift($newestOrderItems); $this->Id = $newestOrderItem->Id; } $result = parent::save($app); return $result; }
} ?> "><br/> quantity: <input type="text" name="quantity" value="<?php if (isset($_REQUEST['quantity'])) { echo htmlspecialchars($_REQUEST['quantity']); } ?> "><br/> description: <input type="text" name="description" value="<?php if (isset($_REQUEST['description'])) { echo htmlspecialchars($_REQUEST['description']); } ?> "><br/> notes: <input type="text" name="notes" value="<?php if (isset($_REQUEST['notes'])) { echo htmlspecialchars($_REQUEST['notes']); } ?> "><br/> <input type="submit"> <input type="hidden" name="go"> </form> <?php include '../infusionsoft.php'; include 'testUtils.php'; if (isset($_REQUEST['go'])) { $out = Infusionsoft_InvoiceService::addOrderItem($_REQUEST['invoiceId'], $_REQUEST['productId'], $_REQUEST['type'], $_REQUEST['price'], $_REQUEST['quantity'], $_REQUEST['description'], $_REQUEST['notes']); var_dump($out); }