Generate Token

Du er her:
Anslået læsetid: 2 min

The API function ‘generate_token’ is used to hide the final URL that the purchaser is being sent to and making sure it is not manipulated before the purchaser gets to the payment window.

The API function returns a JSON response containing the final URL to forward the purchaser to.

To use this function you need to meet the following criteria:

  • Have received a integration code after going through our onboarding process
  • Having saved this code in integration settings in our admin portal

Please take a look at the following code example here.

TIP You can open the file with notepad, if you do not have an editor for viewing source code.

To call the function you need to make a cURL(GET) request with the following parameters:

Parameter Name Description
currency ISO 4217 currency code to use in the transaction. For a full list look here.
merchantid Your merchantid at YourPay.
orderid The orderid you want to use for the transaction
lang The language culture name for the language to use in the payment window. For a list of names look here.
version Which version of the payment window to use. Leave this setting at 107, unless you know what you’re doing.
amount The amount to charge on the purchasers credit card in the subunit of the selected currency.
time Unix timestamp of the moment of the transaction.
accepturl The URL that the purchaser is forwarded to after the transaction is complete. Normally a thank you page.
shopplatform Which shopplatform the call is being made from. WooCommerce, PrestaShop etc.
ct OPTIONAL: If the transaction fee should be forwarded to the purchaser to pay.
checksum The checksum is a sha1 hashed string composed to the orderid, version, merchantid, amount, currency, time & integrationcode. We make the same hash serverside and compare the two. If the hashes mismatch we do not return the final URL.
function The name of the function you’re trying to call.

In the code example it is a requirement that you include your integration code in the $IntegrationCode variable, in order to generate the correct checksum.

Here is come test data, remember to replace the test data with your own.

$IntegrationCode = "qwe"; //Input your integration code here. Can be found in our admin portal under integration settings. $request['currency'] = "208"; // ISO 4217 currency code. For a full list look here: $request['merchantid'] = "600124445"; //Your merchantid at yourpay. $request['orderid'] = "TEST"; //Orderid $request['lang'] = "da-dk"; //language culture name of the language you want on the payment window. $request['version'] = "107"; //Leave this default '107' unless you know what you're doing. $request['amount'] = "100"; // 100 = 1 DKK, SEK, EUR $request['time'] = time(); //Unixtimestamp of the moment the transaction started. $request['accepturl'] = ""; //URL to forward the purchaser to when the transaction is complete, normally a thank you page. $request['shopplatform'] = "Own"; //Which shopplatform are you making the request from? WooCommerce, prestashop etc. $request['ct'] = "off"; //If the transaction fee should be forwarded to the purchaser to pay. $request['checksum'] = sha1($request['orderid'] . $request['version'] . $request['merchantid'] . $request['amount'] . $request['currency'] . $request['time'] . $IntegrationCode); $request['function'] = "generate_token"; //The API function you're calling.

If you upload the code example and navigate to it in your browser, it will then immediately make the call. If the checksum in the call match the one we create serverside, you will receive a JSON response with the final URL to forward the purchaser to, otherwise you will get the response “manipulated”.