Create a payment through PHP

If you want to create a payment function on your website, or your want to use Yourpay as a payment solution on a platform, which we don’t have a plugin in for, it is possible with some technical capabilities.

The code example shows and describes how to insert our payment window in your own code.

It is important that  “http://” or “https://” is inserted in front of the URL.

Be aware that you need a Yourpay account in order to receive payments. You can create a free account here.

$request = array();
$request['function'] = 'generate_token'; //This is the name of the function we would like to use
$request['merchant_token']='INSERT'; //enter your merchant token from your Yourpay account
$request['MerchantNumber'] = 'INSERT'; //replace the last merchantID accordint to your Yourpay account
$request['ShopPlatform']='INSERT'; //enter the name of the platform used
$request['amount'] = 'INSERT'; //replace AMOUNT with the amount you want to get from the customer
$request['currency']='INSERT'; //enter the currency text you would like to use, DKK, EUR etc.
$request['accepturl']='INSERT'; //enter the accepturl, the customer should be forwarded to
$request['callbackurl']='INSERT'; //enter the callback url, where you would like to store the order

$result = json_decode(json_decode(v4requestresponse($request)));

    header("Location: ".$result->content->full_url);

function v4requestresponse($data) {

    $url = "https://webservice.yourpay.dk/v4.3/".$data['function'];
    $fields_string = [];
    foreach($data as $key=>$value){
        $fields_string[$key] = urlencode($value);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields_string));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $server_output = curl_exec ($ch);
    curl_close ($ch);

    return json_encode($server_output);


You can find more documentation in our API – Generate Token.

Didn't find what you were searching for?

Was this article helpful?
Dislike 0
Views: 59

Fandt du ikke svar på det du søgte?