Skip to content

Performing a Payment

ofetisov edited this page Aug 15, 2016 · 12 revisions

Check that you have initialized the SDK before attempting to make a payment.

Create payment

To make a new payment with full card details:

    $payment = $judopay->getModel('Payment');
    $payment->setAttributeValues(
        array(
            'judoId' => 'your_judo_id',
            'yourConsumerReference' => '12345',
            'yourPaymentReference' => '12345',
            'amount' => 1.01,
            'currency' => 'GBP',
            'cardNumber' => '4976000000003436',
            'expiryDate' => '12/15',
            'cv2' => 452
        )
    );

You can check on the required fields and the format of each field in the Judopay REST API reference.

Validating the payment

If you need to check a payment before actually processing you can send validate request and we'll perform our internal checks without sending it to consumer's bank.

    $response = $payment->validate();
    if ($response['code'] === 20) {
        echo 'Validation passed successfully.';
    } else {
        echo 'There were some problems while processing your request';
    }

Please note we can only check the card payment against our own systems. Your payment may still be declined by your consumer's issuing bank.

Check the payment result

And after that you need to send the request to the API. Your code will look like that:

    $response = $payment->create();
    if ($response['result'] === 'Success') {
        echo 'Payment succesful';
    } else {
        echo 'There were some problems while processing your payment';
    }

If the payment is successful, you'll receive a response array like this:

Array
	(
	    [receiptId] => 520882
	    [type] => Payment
	    [createdAt] => 2014-08-18T16:28:39.6164+01:00
	    [result] => Success
	    [message] => AuthCode: 476590
	    [judoId] => 100978394
	    [merchantName] => Joe Bloggs
	    [appearsOnStatementAs] => JudoPay/JoeBlo
	    [originalAmount] => 1.01
	    [netAmount] => 1.01
	    [amount] => 1.01
	    [currency] => GBP
	    [cardDetails] => Array
	        (
	            [cardLastfour] => 3436
	            [endDate] => 1215
	            [cardToken] => mw51OLKsXxm0J49qb5uVj6KJGNOgledk
	            [cardType] => 1
	        )
	
	    [consumer] => Array
	        (
	            [consumerToken] => n1uLVW6OirKhR693
	            [yourConsumerReference] => 12345
	        )
	
	    [yourPaymentReference] => 12345
	)

Also important to handle different exceptions in your code. See more details in our Error handling section.

Clone this wiki locally