Created
April 10, 2014 20:07
-
-
Save chrisdpeters/10418143 to your computer and use it in GitHub Desktop.
Paying an invoice partially via Infusionsoft SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cffunction name="payInvoicePartially" returntype="struct" hint="Creates partial payment and applies to invoice. Based on the method found here: https://github.com/novaksolutions/infusionsoft-php-sdk/blob/master/Infusionsoft/InvoiceService.php" output="false"> | |
<cfargument name="contactId" type="numeric" required="true"> | |
<cfargument name="invoiceId" type="numeric" required="true"> | |
<cfargument name="creditCardId" type="numeric" required="true"> | |
<cfargument name="merchantAccountId" type="numeric" required="true"> | |
<cfargument name="notes" type="string" required="false" default=""> | |
<cfargument name="bypassCommissions" type="boolean" required="false" default="false"> | |
<cfscript> | |
local.sdk = CreateObject("component", "com.liquifusion.infusionsoft.core.Sdk").init( | |
subDomain=variables.instance.id, | |
apiKey=variables.instance.key | |
); | |
local.dummyInvoiceId = local.sdk.createBlankOrder(arguments.contactId, "Web payment - partial", Now(), 0, 0); | |
try { | |
// Wrapping this in `WriteDump` makes this call work. It doesn't work without it for some reason | |
WriteDump(local.sdk.addOrderItem(local.dummyInvoiceId, 0, 3, arguments.amount, 1, "Web payment", "")); | |
local.invoice = this.findInvoiceByContactAndId(arguments.contactId, local.dummyInvoiceId); | |
// Wrapping this in `WriteDump` makes this call work. It doesn't work without it for some reason | |
WriteDump(local.sdk.update( | |
table="Job", | |
id=local.invoice.id, | |
values={"OrderStatus"=JavaCast("string", "Pending")} | |
)); | |
local.result = local.sdk.chargeInvoice( | |
local.invoice.id, | |
"Web payment", | |
arguments.creditCardId, | |
arguments.merchantAccountId, false | |
); | |
} | |
catch (any e) { | |
// Wrapping this in `WriteDump` makes this call work. It doesn't work without it for some reason | |
WriteDump(local.sdk.deleteInvoice(local.dummyInvoiceId)); | |
return { successful=false }; | |
} | |
if (IsStruct(local.result) && StructKeyExists(local.result, "successful") && IsBoolean(local.result.successful) && local.result.successful) { | |
// Wrapping this in `WriteDump` makes this call work. It doesn't work without it for some reason | |
WriteDump(local.sdk.addManualPayment( | |
arguments.invoiceId, | |
arguments.amount, | |
Now(), | |
"Credit Card", "Partial payment - web", | |
false | |
)); | |
// Wrapping this in `WriteDump` makes this call work. It doesn't work without it for some reason | |
WriteDump(local.sdk.update( | |
table="Job", | |
id=local.invoice.id, | |
values={ "OrderStatus"=JavaCast("string", "Successful") } | |
)); | |
} | |
else { | |
local.sdk.deleteInvoice(local.dummyInvoiceId); | |
local.result.successful = false; | |
} | |
</cfscript> | |
<cfreturn local.result> | |
</cffunction> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment