Examples
PHP
Below is a full example on how to integrate Payonic Dynamic Fields, Dynamic Payment Strip and CIT token payment using PHP
<?php // // Create the dynamic fields payment session // $merchantid = "4f4e2451482d441ead8e2862369727d0"; $apikey = "d8d88580acdc4025a16b7e1ae84045ca"; $amount = 10; $currency = "DKK"; $reference = "payonic-" . rand(1000, 10000); $clientwalletaccountemailaddress = "noreply@cardtokens.io"; $payonichostedfieldsurl = "https://api.test.payonic.com/api/initdynamic"; $paymenturl = ""; $ch = curl_init( $payonichostedfieldsurl ); $payload = json_encode( array( "merchantid"=> $merchantid, "amount" => $amount, "currency" => $currency, "reference" => $reference, "clientwalletaccountemailaddress" => $clientwalletaccountemailaddress, "accepturl" => "", "cancelurl" => "", "notificationurl" => "" , "domain" => "www.fakturu.com", "idpan" => "containerpan", "idexpmonth" => "containerexpmonth", "idexpyear" => "containerexpyear", "idchallenge" => "containerchallenge", ) ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'x-api-key:' . $apikey)); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $result = curl_exec($ch); curl_close($ch); $jobj = json_decode($result); // // If the dynamic fields payment session could not be created // then "die" in this example // if ($jobj->sessionid == null) { die("Could not create dynamic fields payment session!"); } ?> <html lang="en-US"> <head> <title>Payonic hosted fields example</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> <script src="<?= $jobj->dfurlscriptinclude ?>"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> .jumbotron { background-color: #FFFFFF !important; } </style> </head> <body> <div class="jumbotron text-center"> <h1>Payonic Hosted Fields</h1> <p>Example on how to integrate and initialize using PHP</p> <section class="jumbotron text-center" id="divDynamicFields" style="display: block;"> <div class="container"> <div class="row"> <div class="col-md-3 text-right" style="text-align: right;"><label for="cardNumber">Card number</label></div> <div class="col-md-6" id="containerpan"></div> <div class="col-md-3 text-right"> </div> </div> <div class="row"> <div class="col-md-3 text-right" style="text-align: right;"><label for="cardNumber">Expire month / year</label></div> <div class="col-md-3" id="containerexpmonth"></div> <div class="col-md-3" id="containerexpyear"></div> <div class="col-md-3 text-right"> </div> </div> <div class="row"> <div class="col-md-3 text-right" style="text-align: right;"></div> <div class="col-md-6"> <button type="button" class="btn btn-primary w-100" id="btnConfirm" onclick="goPay();" style="width: 100%">PAY <?= $currency ?> <?= number_format($amount / 100, 2, ",", ".") ?></button> </div> <div class="col-md-3 text-right"> </div> </div> <div class="row" style="margin-top: 30px; display: none;" id="divPaymentFailed"> <div class="col-md-3 text-right" style="text-align: right;"></div> <div class="col-md-6"> <label class="text-danger" id="divPaymentFailedText"></label> </div> <div class="col-md-3 text-right"> </div> </div> </div> </section> <section class="jumbotron text-center" id="containerchallenge" ></section> </div> <script> $( document ).ready(function() { var req = { jsinitsuccess: initDynamicSuccess, jspaymentsuccess: paymentSuccess, jspaymentstarted: paymentStarted, jspaymentfailed: paymentFailed, } initDynamic(req) }); function initDynamicSuccess(jobj) { $("#divStartPayment").hide(); $("#divDynamicFields").show(); } function paymentStarted() { $("#divPaymentFailed").hide(); $('#btnConfirm').prop('disabled', true); } function paymentFailed(failedReason) { $("#divDynamicFields").show(); $("#divPaymentFailed").show(); $("#divPaymentFailedText").html(failedReason) $('#btnConfirm').prop('disabled', false); } function newPayment() { location.href = "/pay/test/dynamic"; } function paymentSuccess(jobj) { $("#containerchallenge").hide(); if (jobj.approved) { var paymentid = jobj.paymentid; var tokenid = jobj.tokenid; alert("Payment approved with paymentid: " + paymentid + " and tokenid: " + tokenid); location.href = location.href; } } </script> </body> </html>
<?php // // Create the dynamic fields payment session // $merchantid = "4f4e2451482d441ead8e2862369727d0"; $apikey = "d8d88580acdc4025a16b7e1ae84045ca"; $amount = 10; $currency = "DKK"; $reference = "payonic-" . rand(1000, 10000); $clientwalletaccountemailaddress = "noreply@cardtokens.io"; $payonichostedfieldsurl = "https://api.test.payonic.com/api/initdynamic"; $ch = curl_init( $payonichostedfieldsurl ); $payload = json_encode( array( "merchantid"=> $merchantid, "amount" => $amount, "currency" => $currency, "reference" => $reference, "clientwalletaccountemailaddress" => $clientwalletaccountemailaddress, "accepturl" => "", "cancelurl" => "", "notificationurl" => "" , "idpaybutton" => "containerpaybutton", "idccsingle" => "containerccsingle", ) ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'x-api-key:' . $apikey)); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $result = curl_exec($ch); curl_close($ch); $jobj = json_decode($result); // // If the dynamic fields payment session could not be created // then "die" in this example // if ($jobj->sessionid == null) { die("Could not create dynamic fields payment session!"); } ?> <html lang="en-US"> <head> <title>Payonic hosted fields example</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> <script src="<?= $jobj->dfurlscriptinclude ?>"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> .jumbotron { background-color: #FFFFFF !important; } </style> </head> <body> <div class="jumbotron text-center"> <h1>Payonic Hosted Fields</h1> <p>Example on how to integrate and initialize using PHP</p> <section class="jumbotron text-center" id="divDynamicFields" style="display: block;"> <div class="container"> <div class="row"> <div class="col-md-2 text-right" style="text-align: right;"></div> <div class="col-md-8" id="containerccsingle"></div> <div class="col-md-2 text-right"> </div> </div> <div class="row"> <div class="col-md-3 text-right" style="text-align: right;"></div> <div class="col-md-6"> <button type="button" class="btn btn-primary w-100" id="btnConfirm" onclick="goPay();" style="width: 100%">PAY <?= $currency ?> <?= number_format($amount / 100, 2, ",", ".") ?></button> </div> <div class="col-md-3 text-right"> </div> </div> <div class="row" style="margin-top: 30px; display: none;" id="divPaymentFailed"> <div class="col-md-3 text-right" style="text-align: right;"></div> <div class="col-md-6"> <label class="text-danger" id="divPaymentFailedText"></label> </div> <div class="col-md-3 text-right"> </div> </div> </div> </section> <section class="jumbotron text-center" id="divDynamicFieldsChallenge" ></section> </div> <script> $( document ).ready(function() { var req = { jsinitsuccess: initDynamicSuccess, jspaymentsuccess: paymentSuccess, jspaymentstarted: paymentStarted, jspaymentfailed: paymentFailed, } initDynamic(req) }); function initDynamicSuccess(jobj) { $("#divStartPayment").hide(); $("#divDynamicFields").show(); } function paymentStarted() { $("#divPaymentFailed").hide(); $('#btnConfirm').prop('disabled', true); } function paymentFailed(failedReason) { $("#divDynamicFields").show(); $("#divPaymentFailed").show(); $("#divPaymentFailedText").html(failedReason) $('#btnConfirm').prop('disabled', false); $("#divDynamicFieldsChallenge").hide(); } function paymentSuccess(jobj) { if (jobj.approved) { $("#divDynamicFieldsChallenge").hide(); var paymentid = jobj.paymentid; var tokenid = jobj.tokenid; alert("Payment approved with paymentid: " + paymentid + " and tokenid: " + tokenid); location.href = location.href; } } </script> </body> </html>
<?php // // Create the dynamic fields payment session // $merchantid = "4f4e2451482d441ead8e2862369727d0"; $apikey = "d8d88580acdc4025a16b7e1ae84045ca"; $amount = 10; $currency = "DKK"; $reference = "payonic-" . rand(1000, 10000); $clientwalletaccountemailaddress = "noreply@cardtokens.io"; $payonichostedfieldsurl = "https://api.test.payonic.com/api/initdynamic"; $ch = curl_init( $payonichostedfieldsurl ); $payload = json_encode( array( "merchantid"=> $merchantid, "amount" => $amount, "currency" => $currency, "reference" => $reference, "clientwalletaccountemailaddress" => $clientwalletaccountemailaddress, "accepturl" => "", "cancelurl" => "", "notificationurl" => "" , "idpaybutton" => "containerpaybutton", "tokenid" => "1e1cdb43e59d446e9e0024503ea7a361" ) ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'x-api-key:' . $apikey)); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $result = curl_exec($ch); curl_close($ch); $jobj = json_decode($result); // // If the dynamic fields payment session could not be created // then "die" in this example // if ($jobj->sessionid == null) { die("Could not create dynamic fields payment session!"); } ?> <html lang="en-US"> <head> <title>Payonic hosted fields example</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> <script src="<?= $jobj->dfurlscriptinclude ?>"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> .jumbotron { background-color: #FFFFFF !important; } </style> </head> <body> <div class="jumbotron text-center"> <h1>Payonic Hosted Fields</h1> <p>Example on how to perform a "top-up" operation using PHP</p> <section class="jumbotron text-center" id="divDynamicFields" style="display: block;"> <div class="container"> <div class="row"> <div class="col-md-3 text-right" style="text-align: right;"></div> <div class="col-md-6"> <button type="button" class="btn btn-primary w-100" id="btnConfirm" onclick="goPay();" style="width: 100%">PAY <?= $currency ?> <?= number_format($amount / 100, 2, ",", ".") ?></button> </div> <div class="col-md-3 text-right"> </div> </div> <div class="row" style="margin-top: 30px; display: none;" id="divPaymentFailed"> <div class="col-md-3 text-right" style="text-align: right;"></div> <div class="col-md-6"> <label class="text-danger" id="divPaymentFailedText"></label> </div> <div class="col-md-3 text-right"> </div> </div> </div> </section> <section class="jumbotron text-center" id="divDynamicFieldsChallenge" ></section> </div> <script> $( document ).ready(function() { var req = { jsinitsuccess: initDynamicSuccess, jspaymentsuccess: paymentSuccess, jspaymentstarted: paymentStarted, jspaymentfailed: paymentFailed, } initDynamic(req) }); function initDynamicSuccess(jobj) { $("#divStartPayment").hide(); $("#divDynamicFields").show(); } function paymentStarted() { $("#divPaymentFailed").hide(); $('#btnConfirm').prop('disabled', true); } function paymentFailed(failedReason) { $("#divDynamicFields").show(); $("#divPaymentFailed").show(); $("#divPaymentFailedText").html(failedReason) $('#btnConfirm').prop('disabled', false); $("#divDynamicFieldsChallenge").hide(); } function paymentSuccess(jobj) { if (jobj.approved) { $("#divDynamicFieldsChallenge").hide(); var paymentid = jobj.paymentid; var tokenid = jobj.tokenid; alert("Payment approved with paymentid: " + paymentid + " and tokenid: " + tokenid); location.href = location.href; } } </script> </body> </html>