Skip to content

Instantly share code, notes, and snippets.

@rbishop
Last active August 29, 2015 14:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rbishop/cae4ec34f6a159c1038d to your computer and use it in GitHub Desktop.
Cardinal Centinel Gateway Example
credit_card = ActiveMerchant::Billing::CreditCard.new(cc_number, cc_info_hash)
gateway = ActiveMerchant::Billing::CardinalCentinelGateway.new(
ProcessorId: '123',
MerchantId: '456',
TransactionPwd: 'p4ssw0rd'
)
lookup_response = gateway.authorize(amount, credit_card)
if lookup_response.enrolled?
# redirect the user to the 3d Secure ACS Url via HTTP POST
# A common thing to do here that I've seen is render a partial that
# is just a form that submits on page load. An example of this form
# can be seen in the other file in this gist.
form_values = {
pa_req: lookup_response.payload,
acs_url: lookup_response.acs_url,
md: lookup_response.transaction_id,
term_url: 'A URL on your server for the bank to redirect to after successful verification'
}
render 'secure_verify_rediect_form', form_values
else
# Some other payment flow here
end
# After the user completes the off site verification, The bank will
# send a POST request to the TermUrl you specified above.
# This TermUrl will receive the PaRes and MD in the params.
# You can complete the final step using these params.
auth_response = gateway.secure_verify(params['PaRes'], params['MD'])
# Success is determined by the absence of errors as well as
# the presnce of a Xid, Cavv and EciFlag
if auth_response.success?
# handle success
else
# handle failure
end
<html>
<body onload="document.frmLaunch.submit();">
<form name="frmLaunch" method="POST" action="<%= acs_url %>">
<input type="hidden" name="PaReq" value="<%= pa_req %>">
<input type="hidden" name="TermUrl" value="<%= term_url %>">
<input type="hidden" name="MD" value="<%= md %>">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment