Skip to content

Commit

Permalink
Updated tutorial fixing code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
akakjs committed Mar 17, 2015
1 parent 637eed0 commit fb0c46c
Showing 1 changed file with 82 additions and 82 deletions.
164 changes: 82 additions & 82 deletions tutorials/judo_making_a_payment.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

First, configure a Judopay object with your authentication credentials (as described in the Getting Started guide).

$judopay = new \Judopay(
array(
'apiToken' => 'your-token,
'apiSecret' => 'your-secret',
'judoId' => 'your-judo-id
)
);
$judopay = new \Judopay(
array(
'apiToken' => 'your-token,
'apiSecret' => 'your-secret',
'judoId' => 'your-judo-id
)
);

To make a new payment with full card details:

$payment = $judopay->getModel('Payment');
$payment->setAttributeValues(
array(
'judoId' => getenv('JUDO_ID'),
'yourConsumerReference' => '12345',
'yourPaymentReference' => '12345',
'amount' => 1.01,
'currency' => 'GBP',
'cardNumber' => '4976000000003436',
'expiryDate' => '12/15',
'cv2' => 452
)
);
$payment = $judopay->getModel('Payment');
$payment->setAttributeValues(
array(
'judoId' => getenv('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_.

Expand All @@ -34,60 +34,60 @@ To send the request to the API, call:

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
)
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
)

## Error handling

When making a payment, there are a number of different scenarios that can arise. It is important to handle all of the different exceptions in your code.

try {
$response = $payment->create();
} catch (\Judopay\Exception\ValidationError $e) {
// There were missing or invalid fields
echo $e->getSummary();
print_r($e->getModelErrors()); // Array of model errors
} catch (\Judopay\Exception\BadRequest $e) {
// Invalid parameters were supplied to Judopay's API
echo $e->getSummary();
print_r($e->getModelErrors()); // Array of model errors
} catch (\Judopay\Exception\ NotAuthorized $e) {
// You're not authorized to make the request - check credentials and permissions in the Judopay portal
} catch (\Judopay\Exception\NotFound $e) {
// The resource was not found
} catch (\Judopay\Exception\Conflict $e) {
// Rate limiting - you have made too many requests to the Judopay API
} catch (\Exception $e) {
// A problem occurred outside the Judopay SDK
}
try {
$response = $payment->create();
} catch (\Judopay\Exception\ValidationError $e) {
// There were missing or invalid fields
echo $e->getSummary();
print_r($e->getModelErrors()); // Array of model errors
} catch (\Judopay\Exception\BadRequest $e) {
// Invalid parameters were supplied to Judopay's API
echo $e->getSummary();
print_r($e->getModelErrors()); // Array of model errors
} catch (\Judopay\Exception\ NotAuthorized $e) {
// You're not authorized to make the request - check credentials and permissions in the Judopay portal
} catch (\Judopay\Exception\NotFound $e) {
// The resource was not found
} catch (\Judopay\Exception\Conflict $e) {
// Rate limiting - you have made too many requests to the Judopay API
} catch (\Exception $e) {
// A problem occurred outside the Judopay SDK
}

## Logging

Expand All @@ -101,16 +101,16 @@ https://github.com/Seldaek/monolog

For example, to log debug messages to the file 'judopay.log' using Monolog:

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('Judopay');
$logger->pushHandler(new StreamHandler('judopay.log'));
$judopay = new \Judopay(
array(
'apiToken' => 'your-token,
'apiSecret' => 'your-secret',
'judoId' => 'your-judo-id,
'logger' => $logger
)
);
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$logger = new Logger('Judopay');
$logger->pushHandler(new StreamHandler('judopay.log'));
$judopay = new \Judopay(
array(
'apiToken' => 'your-token,
'apiSecret' => 'your-secret',
'judoId' => 'your-judo-id,
'logger' => $logger
)
);

0 comments on commit fb0c46c

Please sign in to comment.