Server SDKs
Server SDK Integration
Migrating from PHP SDK to Direct API Integration
this guide provides helpful information on migrating your authentication, payments and payment management functions from the legacy php sdk code, with the equivalent direct api integration calls see the transaction api reference docid\ bcxnm5keok nlnrztafut documentation for full schema details and descriptions on each endpoint and try out requests authentication use the following method to authenticate requests when calling directly to our transaction api tokensecretauth the token and secret pair for more details, see authentication methods docid\ ylkw5coh5nqnfq3j wjk2 $judopay = new judopay(\[ 'apitoken' => 'your token', 'apisecret' => 'your secret', 'judoid' => 'your judo id', 'useproduction' => true ]);\<?php class judoapiclient { private $apitoken; private $apisecret; private $baseurl; private $apiversion; public function construct($apitoken, $apisecret, $useproduction = true) { $this >apitoken = $apitoken; $this >apisecret = $apisecret; $this >baseurl = $useproduction ? 'https //api judopay com/' 'https //api sandbox judopay com/'; $this >apiversion = '6 23'; } private function getheaders() { return \[ 'content type application/json', 'accept application/json', 'authorization basic ' base64 encode($this >apitoken ' ' $this >apisecret), 'api version ' $this >apiversion, 'user agent directapi php' ]; } private function makerequest($method, $endpoint, $data = null) { $url = $this >baseurl $endpoint; $ch = curl init(); curl setopt($ch, curlopt url, $url); curl setopt($ch, curlopt returntransfer, true); curl setopt($ch, curlopt httpheader, $this >getheaders()); curl setopt($ch, curlopt customrequest, $method); curl setopt($ch, curlopt ssl verifypeer, true); curl setopt($ch, curlopt ssl verifyhost, 2); if ($data) { curl setopt($ch, curlopt postfields, json encode($data)); } $response = curl exec($ch); $httpcode = curl getinfo($ch, curlinfo http code); $error = curl error($ch); curl close($ch); if ($error) { throw new exception("curl error " $error); } $decodedresponse = json decode($response, true); if ($httpcode >= 400) { throw new exception("api error " $response, $httpcode); } return $decodedresponse; } } ?> payments to process 3d secure 2 transactions , we highly recommend using our web sdk docid 40dwe6lbub7vdkza1qydc for any assistance with this, please contact customer support preauths $preauth = $judopay >getmodel('preauth'); $preauth >setattributevalues(\[ 'yourconsumerreference' => '12345', 'yourpaymentreference' => 'preauth 001', 'judoid' => 'your judo id', 'amount' => 25 00, 'currency' => 'gbp', 'cardnumber' => '4976000000003436', 'expirydate' => '12/25', 'cv2' => '452' ]); $response = $preauth >create();public function createpreauth($preauthdata) { $endpoint = 'transactions/preauths'; $requestdata = \[ 'yourconsumerreference' => $preauthdata\['yourconsumerreference'], 'yourpaymentreference' => $preauthdata\['yourpaymentreference'], 'judoid' => $preauthdata\['judoid'], 'amount' => $preauthdata\['amount'], 'currency' => $preauthdata\['currency'], 'cardnumber' => $preauthdata\['cardnumber'], 'expirydate' => $preauthdata\['expirydate'], 'cv2' => $preauthdata\['cv2'] ]; return $this >makerequest('post', $endpoint, $requestdata); } payments $payment = $judopay >getmodel('payment'); $payment >setattributevalues(\[ 'yourconsumerreference' => '12345', 'yourpaymentreference' => 'payment 001', 'judoid' => 'your judo id', 'amount' => 10 50, 'currency' => 'gbp', 'cardnumber' => '4976000000003436', 'expirydate' => '12/25', 'cv2' => '452' ]); $response = $payment >create(); public function createpayment($paymentdata) { $endpoint = 'transactions/payments'; $requestdata = \[ 'yourconsumerreference' => $paymentdata\['yourconsumerreference'], 'yourpaymentreference' => $paymentdata\['yourpaymentreference'], 'judoid' => $paymentdata\['judoid'], 'amount' => $paymentdata\['amount'], 'currency' => $paymentdata\['currency'], 'cardnumber' => $paymentdata\['cardnumber'], 'expirydate' => $paymentdata\['expirydate'], 'cv2' => $paymentdata\['cv2'] ]; return $this >makerequest('post', $endpoint, $requestdata); } // usage $api = new judoapiclient('your token', 'your secret'); $response = $api >createpayment(\[ 'yourconsumerreference' => '12345', 'yourpaymentreference' => 'payment 001', 'judoid' => 'your judo id', 'amount' => 10 50, 'currency' => 'gbp', 'cardnumber' => '4976000000003436', 'expirydate' => '12/25', 'cv2' => '452' ]); token payments $tokenpayment = $judopay >getmodel('tokenpayment'); $tokenpayment >setattributevalues(\[ 'yourconsumerreference' => '12345', 'yourpaymentreference' => 'token payment 001', 'judoid' => 'your judo id', 'amount' => 15 75, 'currency' => 'gbp', 'consumertoken' => 'consumer token 123', 'cardtoken' => 'card token 456', 'cv2' => '452' ]); $response = $tokenpayment >create();public function createtokenpayment($tokendata) { $endpoint = 'transactions/payments'; $requestdata = \[ 'yourconsumerreference' => $tokendata\['yourconsumerreference'], 'yourpaymentreference' => $tokendata\['yourpaymentreference'], 'judoid' => $tokendata\['judoid'], 'amount' => $tokendata\['amount'], 'currency' => $tokendata\['currency'], 'consumertoken' => $tokendata\['consumertoken'], 'cardtoken' => $tokendata\['cardtoken'], 'cv2' => $tokendata\['cv2'] ]; return $this >makerequest('post', $endpoint, $requestdata); } collections (capture) $collection = $judopay >getmodel('collection'); $collection >setattributevalues(\[ 'receiptid' => '12345678', 'yourpaymentreference' => 'collection 001', 'amount' => 25 00 ]); $response = $collection >create();public function createcollection($collectiondata) { $endpoint = 'transactions/collections'; $requestdata = \[ 'receiptid' => $collectiondata\['receiptid'], 'yourpaymentreference' => $collectiondata\['yourpaymentreference'], 'amount' => $collectiondata\['amount'] ]; return $this >makerequest('post', $endpoint, $requestdata); } // usage $response = $api >createcollection(\[ 'receiptid' => '12345678', 'yourpaymentreference' => 'collection 001', 'amount' => 25 00 ]); refunds $refund = $judopay >getmodel('refund'); $refund >setattributevalues(\[ 'receiptid' => '12345678', 'yourpaymentreference' => 'refund 001', 'amount' => 5 25 ]); $response = $refund >create();public function createrefund($refunddata) { $endpoint = 'transactions/refunds'; $requestdata = \[ 'receiptid' => $refunddata\['receiptid'], 'yourpaymentreference' => $refunddata\['yourpaymentreference'], 'amount' => $refunddata\['amount'] ]; return $this >makerequest('post', $endpoint, $requestdata); } // usage $response = $api >createrefund(\[ 'receiptid' => '12345678', 'yourpaymentreference' => 'refund 001', 'amount' => 5 25 ]); payment management get transaction details $transaction = $judopay >getmodel('gettransaction'); $response = $transaction >find('12345678');public function gettransaction($receiptid) { $endpoint = "transactions/{$receiptid}"; return $this >makerequest('get', $endpoint); } // usage $transaction = $api >gettransaction('12345678'); list transaction details $transactions = $judopay >getmodel('gettransaction'); $response = $transactions >all(0, 20, 'time descending');public function listtransactions($offset = 0, $pagesize = 10, $sort = 'time descending') { $endpoint = "transactions"; $queryparams = http build query(\[ 'offset' => $offset, 'pagesize' => $pagesize, 'sort' => $sort ]); return $this >makerequest('get', $endpoint '?' $queryparams); } // usage $transactions = $api >listtransactions(0, 20, 'time descending'); complete migration example putting it all together \<?php require once 'vendor/autoload php'; $judopay = new judopay(\[ 'apitoken' => 'your token', 'apisecret' => 'your secret', 'judoid' => 'your judo id' ]); try { // create payment $payment = $judopay >getmodel('payment'); $payment >setattributevalues(\[ 'yourconsumerreference' => '12345', 'yourpaymentreference' => 'payment 001', 'amount' => 10 50, 'currency' => 'gbp', 'cardnumber' => '4976000000003436', 'expirydate' => '12/25', 'cv2' => '452' ]); $result = $payment >create(); if ($result\['result'] === 'success') { echo "payment successful " $result\['receiptid']; } } catch (exception $e) { echo "error " $e >getmessage(); } ?>\<?php require once 'judoapiclient php'; $api = new judoapiclient('your token', 'your secret'); try { // create payment $result = $api >createpayment(\[ 'yourconsumerreference' => '12345', 'yourpaymentreference' => 'payment 001', 'judoid' => 'your judo id', 'amount' => 10 50, 'currency' => 'gbp', 'cardnumber' => '4976000000003436', 'expirydate' => '12/25', 'cv2' => '452' ]); if ($api >validateresponse($result)) { echo "payment successful " $result\['receiptid']; } } catch (judoapiexception $e) { echo "api error " $e >getmessage(); echo "http code " $e >gethttpstatuscode(); if ($e >getfielderrors()) { echo "field errors " json encode($e >getfielderrors()); } } ?>