Placér dit indhold fhgfvhbher

Lav selv en betaling via php

Du er her:
Estimeret læsningstid: 1 min

Hvis du selv ønsker at lave en betalingfunktion på din hjemmeside, eller du vil bruge os på en ikke-understøttet platform, er dette muligt hvis du har lidt teknisk snilde.

I det nedenstående kodeeksempel, viser og beskriver vi hvordan du indsætter vores betalingsvindue i din egen kode.

OBS: Vær opmærksom på du behøver en Yourpay konto, for at kunne modtage betalinger. Dette kan du dog gratis oprette på yourpay.io

<?php
$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 you would like to use
$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);

}
?>
Was this article helpful?
Dislike 0
Views: 8
Luk menu
×

Kurv