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 == '') { $success = Infusionsoft_InvoiceService::addManualPayment($this->InvoiceId, $this->PayAmt, $this->PayDate, $this->PayType, $this->PayNote, false, $app); if (!$success) { throw new Infusionsoft_Exception("Failed while saving payment: " . json_encode($this->toArray())); } $this->Id = 'Created, But, Cannot Get Id'; } return true; }
} ?> "><br/> paymentType: <input type="text" name="paymentType" value="<?php if (isset($_REQUEST['paymentType'])) { echo htmlspecialchars($_REQUEST['paymentType']); } ?> "><br/> paymentDescription: <input type="text" name="paymentDescription" value="<?php if (isset($_REQUEST['paymentDescription'])) { echo htmlspecialchars($_REQUEST['paymentDescription']); } ?> "><br/> bypassCommissions: <input type="text" name="bypassCommissions" value="<?php if (isset($_REQUEST['bypassCommissions'])) { echo htmlspecialchars($_REQUEST['bypassCommissions']); } ?> "><br/> <input type="submit"> <input type="hidden" name="go"> </form> <?php include '../infusionsoft.php'; include 'testUtils.php'; if (isset($_REQUEST['go'])) { $out = Infusionsoft_InvoiceService::addManualPayment($_REQUEST['invoiceId'], $_REQUEST['amt'], $_REQUEST['paymentDate'], $_REQUEST['paymentType'], $_REQUEST['paymentDescription'], $_REQUEST['bypassCommissions']); var_dump($out); }