Making a WebPayment

ofetisov edited this page Jun 13, 2017 · 11 revisions

JudoResponsive allows you to easily accept card payments within your WebApp. It supports both desktop and mobile devices and helps to nake your PCI-DSS compliance easier. It also includes card holder verification using 3D-Secure and the Address Verification System (AVS).

Configuration checklist

  • You need to configure the "Success" and "Cancel" URLs for your application, which will be called if the payment is successful and the cancel URL if the payment is aborted.
  • Your API token needs to have the permissions to "create" web payments, you can edit these permissions on the application configuration screen within our merchant dashboard
Include a model

Add model inclusion to your source code:

require 'judopay/models/web_payments/payment'

Provisioning the web payment

Before you can send your user to the judo payment page, you'll need to tell us the details of the web payment using our JudoPay API. Support for this is built into our Ruby SDK:

# Populate the API token and API secret details with the Judopay gem
# from the application you created on our 
Judopay.configure do |config|
	config.judo_id = 12345
	config.api_token = 'your-token'
    config.api_secret = 'your-secret'
end

# Create an instance of the WebPayment Payment model, or you can use the Preauth model 
# if you only want to process a pre-authorisation which you can collect later.
payment = Judopay::WebPayments::Payment.new(
  :judoId => 'your_judo_id',
  :your_consumer_reference => 'xxxxxxxx',
  :your_payment_reference => 'xxxxxxxx',
  :amount => 10.00,
  :currency => 'GBP',
  :clientIpAddress => '127.0.0.1',
  :clientUserAgent => 'Their browser user agent/11.0'
)

# Send the model to the JudoPay API, this provisions your web payment and returns a unique reference along with the 
# URL of the page you'll need to dispatch your users to.

webpayment_details = payment.create

# Here's an example of the Mash returned
# {
#  "post_url"=>"https://pay.judopay-sandbox.com/v1",
#  "reference"=>"4AcAAAkAAAAXAAAABwAAAL2kP2Pk-XatKSeqDvWdlGDvyuKCHCEdTsnEwVZ76TNDVawo4g"
# }

web_payment_reference = webpayment_details.reference
form_post_url = webpayment_details.post_url

Note: Please make sure that you are using a unique Consumer Reference for each different consumer, and a unique Payment Reference for each transaction.

Dispatching your user to judo

You should then dispatch your user to our server using a POST request, this can be done easily by wrapping your "Pay Now" button in a form as follows:

	<form action="<%=form_post_url%>" method="post">
	<input  id="Reference" name="Reference" type="hidden" value="<%=web_payment_reference%>">
	<input type="submit" value="Pay now">
	</form>

Capturing the returned information

Whether payment was successful system returns to pre-configured success URL using a POST request. Included in this POST request are the following form fields:

reference - this is our reference for the web payment.

receipt_id - this is our reference number for the JudoPay API transaction.

card_token - this is the unique reference for your user's card. If you want to process further payments on their card (either as a "saved card" feature, or a reoccurring subscription payment), you must capture this card token.

Please note that you cannot retrieve the card_token later. If you wish to use this card in a future payment (i.e. Pay with your saved card) you will need to capture and store this value.

Verifying the payment

Finally, you should always verify the payment outcome using the JudoPay API, this will protect you from the request tampering.

require 'judopay/models/web_payments/transaction'
# Invoke the find method passing in the reference you obtained above to the WebPayment Transaction class
# (as web payments can either be payments or pre-authorization we have a superclass called transaction).

transaction_details  = Judopay::WebPayments::Transaction.find(web_payment_reference)

# check the value of the "status" to confirm the payment was successful
webpayment_status = transaction_details.status

# webpayment_status should be "Success"
# you can also access a copy of our receipt object using the "receipt" entry.
receipt = transaction_details.receipt
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.