Vent venligst ...


Loading...

Hash - MD5-tjek

Hash - MD5-tjek

Denne artikel beskriver, hvordan du udregner hash-værdien, som sendes til Bambora, og hvordan du kontrollerer hash-værdien, som du modtager fra Bambora.
Bemærk ved betalingsmoduler

Hvis du bruger et af vores betalingsmoduler (open source-moduler), så find din shopløsning på listen her, og klik ind på guiden. Der kan du finde mere information om MD5 under ’Opsætning’.
Bemærk

Husk at sætte ”MD5-sikkerhedstjek” til På acceptside og ved autorisation i din Bambora-administration under Indstillinger -> Betalingssystemet.

Sendt til Bambora

Den hash-værdi, som du sender til (og modtager fra) Bambora, skal bestå af værdien af alle parametre i den rækkefølge, de bliver sendt, samt din MD5-nøgle.
<?php
$merchantRisk = [
    'shippingmethod' => "ShipToAnotherVerifiedAddress",
    'deliverytimeframe' => "SameDayShipping",
    'deliveryemail' => "john.doe@example.com",
    'reorderitemsindicator' => "FirstTime",
    'orderavailability' => "MerchandiseAvailable",
    'preorderavailabilitydate' => "2016-04-30T00:00:00.000Z",
    'giftcard' => [
        'currency' => "SEK",
        'amount' => 123,
        'count' => 1
    ]
];
$accountInformation = [
    'authentication' => [
        'data' => "Example string",
        'method' => "NoAuthentication",
        'timestamp' => "2016-04-30T10:22:56.049Z",
    ],
    'prior3dsauthentication' => [
        'data' => "Example string",
        'method' => "FrictionlessAuthenticationOccurredByAcs",
        'reference' => "0a137f3d-9fcf-4040-b6c7-e596cb79d953",
        'timestamp' => "2016-04-30T10:22:56.049Z"
    ],
    'createdindicator' => "CreatedDuringTransaction",
    'createddate' => "2016-04-30T10:22:56.049Z",
    'changeddate' => "2016-04-30T10:22:56.049Z",
    'nameidenticaltoshippingaddressname' => true,
    'passwordchangeddate' => "2016-04-30T10:22:56.049Z",
    'shippingaddressfirstusedindicator' => "ThisTransaction",
    'shippingaddressfirstuseddate' => "2016-04-30T10:22:56.049Z",
    'shippingaddressidenticaltobillingaddress' => true,
    'transactionspast24hours' => 4,
    'transactionspastyear' => 24,
    'transactionsapprovedpastsixmonths' => 10,
    'paymentaccountcreatedindicator' => "CreatedDuringTransaction",
    'paymentaccountcreateddate' => "2016-04-30T10:22:56.049Z",
    'provisionattemptspast24hours' => 3,
    'suspiciousactivity' => false
];
$invoice = [
    'customer' => [
        'reference' => "Reference",
        'emailaddress' => "test@epay.dk",
        'firstname' => "Jens",
        'lastname' => "Jensen",
        'attention' => "The att.",
        'address' => "Testervej 1",
        'zip' => "9000",
        'city' => "Aalborg",
        'country' => "Denmark",
        'phone' => "+4598139040",
        'state' => "81",
        'homephonenumber' => "+4598139040",
        'workphonenumber' => "+4598139040",
    ],
    'shippingaddress' => [
        'firstname' => "Jens",
        'lastname' => "Jensen",
        'attention' => "The Att.",
        'address' => "Testervej 1",
        'zip' => "9000",
        'city' => "Aalborg",
        'country' => "Denmark",
        'phone' => "+4598139040",
        'state' => "81",
    ],
    'lines' => [
        array(
            'id' => "6",
            'description' => "MacBook",
            'text' => "Product Details",
            'quantity' => 1,
            'price' => 8000,
            'vat' => 25
        ),
        array(
            'id' => "shipping",
            'description' => "Shipping",
            'text' => "Product Details",
            'quantity' => 1,
            'price' => 800,
            'vat' => 25
        )
    ]
];
$paymentWindowRequest= array(
    'merchantnumber' => 'YOUR MERCHANT ID HERE',
    'amount' => '11000',
    'currency' => 'DKK',
    'merchantrisk' => $merchantRisk,
    'accountinformation' => $accountInformation,
    'invoice' => $invoice
);
?>

<script type="text/javascript" src="https://ssl.ditonlinebetalingssystem.dk/integration/ewindow/paymentwindow.js"
        charset="UTF-8">
</script>

<script type="text/javascript">
    paymentwindow = new PaymentWindow({
        <?php
        $hash = "";
        foreach ($paymentWindowRequest as $key => $value) {
            if ($key) {
                if (is_array($value)) {
                    echo "'" . $key . "':'" . json_encode($value, JSON_UNESCAPED_UNICODE) . "' ,\n";
                    $hash .= json_encode($value);
                } else {
                    echo "'" . $key . "': \"" . $value . "\",\n";
                    $hash .= $value;
                }
            }
        }
        $hash = md5($hash . "SecretMD5Key");
        ?>
        'hash': "<?php echo $hash; ?>"
    });
</script>
<input type="button" onclick="paymentwindow.open()" value="Go to payment"/>

Modtaget fra Bambora

Den hash-værdi, som du modtager fra Bambora, består af værdien af alle modtagne GET-parametre undtagen parameteren hash og din MD5-nøgle.
<?php
$params = $_GET;
$var = "";

foreach ($params as $key => $value)
{
    if($key != "hash")
    {
        $var .= $value;
    }
}

$genstamp = md5($var . "SecretMD5Key");

if($genstamp != $_GET["hash"])
{
    echo "Hash is not valid";
    exit();
}
else
{
    //Hash is OK   
}
?>