Plugin Directory

Changeset 2621879


Ignore:
Timestamp:
10/29/2021 09:46:52 AM (4 years ago)
Author:
chaifinport
Message:

promo_discount nil bug fix & field name change fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chaiport-payment/trunk/chaiportGateway.php

    r2607037 r2621879  
    178178function ChaiportVerifySignature($responseObj, $secretKey, $type)
    179179{
     180    $signature_hash = "";
    180181    if ($type == "redirect") {
     182        $queryParams = $responseObj->get_query_params();
     183        $statusTypes = array(
     184            "Success", "Failed"
     185        );
     186        if (in_array($queryParams['status'], $statusTypes)) {
     187            $statusData = $queryParams['status'];
     188        } else {
     189            $statusData = "Success";
     190            $pairs = explode('&', $_SERVER[REQUEST_URI]);
     191            foreach ($pairs as $value) {
     192                if (substr($value, 0, 6) == "status=") {
     193                    $val = explode($value, '=')[1];
     194                    if (in_array($val, $statusTypes)){
     195                        $statusData = $val;
     196                    }
     197                }
     198            }
     199        }
     200        $signature_hash = $queryParams['signature_hash'];
    181201        $data = array(
    182             'order_ref' => $responseObj['order_ref'],
    183             'channel_order_ref' => $responseObj['channel_order_ref'],
    184             'merchant_order_ref' => $responseObj['merchant_order_ref'],
    185             'status' => $responseObj['status']
     202            'order_ref' => $queryParams['order_ref'],
     203            'channel_order_ref' => $queryParams['channel_order_ref'],
     204            'merchant_order_ref' => $queryParams['merchant_order_ref'],
     205            'status' => $statusData
    186206        );
    187207    } else if ($type == "webhook") {
     208        $signature_hash = $responseObj['signature_hash'];
    188209        $data = array(
    189210            'currency' => $responseObj['currency'],
     
    198219        );
    199220    }
    200 
    201221    ksort($data);
    202222    $message = http_build_query($data);
    203223    $hash_value = base64_encode(hash_hmac('sha256', $message, $secretKey, true));
    204224
    205     if ($hash_value !== $responseObj['signature_hash']) {
     225    if ($hash_value !== $signature_hash) {
    206226        echo "Hash verification failed, not from valid source";
    207227        return false;
     
    280300    // updating order
    281301    if (($order != false) && ($isSignatureValid == true)) {
    282         $status = $data["status"];
     302        $statusTypes = array(
     303            "Success", "Failed"
     304        );
     305        if (in_array($data['status'], $statusTypes)) {
     306            $status = $data['status'];
     307        } else {
     308            $status = "Success";
     309            $pairs = explode('&', $_SERVER[REQUEST_URI]);
     310            foreach ($pairs as $value) {
     311                if (substr($value, 0, 6) == "status=") {
     312                    $val = explode($value, '=')[1];
     313                    if (in_array($val, $statusTypes)){
     314                        $status = $val;
     315                    }
     316                }
     317            }
     318        }
    283319        $orderRef = $data["order_ref"];
    284320        $note = "--- Redirect Update ---\n";
     
    671707                "back_url" => get_bloginfo('url') . "/checkout/",
    672708                "shipping_charges" => 0.0,
     709                "promo_discount" => 0
    673710            );
    674711
Note: See TracChangeset for help on using the changeset viewer.