Skip to content

Instantly share code, notes, and snippets.

@jdeoliveira
Created June 29, 2012 16:37
Show Gist options
  • Save jdeoliveira/3019061 to your computer and use it in GitHub Desktop.
Save jdeoliveira/3019061 to your computer and use it in GitHub Desktop.
Analyze credit request PHP script
<scripting:component doc:name="Analyze credit request">
<scripting:script engine="php">
<scripting:text>
<![CDATA[
<?php
$log->info("Hello from PHP, mule!");
$request = json_decode($payload, true);
if (strcmp(substr($request["customerId"], 0, 3), "ABC") == 0) $factor = 3;
else if (strcmp(substr($request["customerId"], 0, 3), "DEF") == 0) $factor = 2;
if ($request["requestedAmount"] > ($factor * $request["averageIncome"])) {
$message->setOutboundProperty("outcome", "rejected");
$request["maxAmount"] = ($factor * $request["averageIncome"]);
} else {
$message->setOutboundProperty("outcome", "approved");
}
return json_encode($request);
?>
]]>
</scripting:text>
</scripting:script>
</scripting:component>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment