Plugin Directory

Changeset 3377481


Ignore:
Timestamp:
10/13/2025 11:49:06 AM (6 months ago)
Author:
grilabs
Message:

API V3 issues fixed.

Location:
tami-payment
Files:
130 added
5 edited

Legend:

Unmodified
Added
Removed
  • tami-payment/trunk/lib/HashGenerator.php

    r3229701 r3377481  
    5454    private $fixed_k_value;
    5555    private $fixed_kid_value;
     56    private $api_v3_enabled = false;
    5657
    5758    public function __construct(
     
    6768        $this->fixed_k_value   = $kValue;
    6869        $this->fixed_kid_value = $kidValue;
     70        $this->api_v3_enabled = $this->fixed_k_value !== TamiPaymentClient::FIXED_K_VALUE;
    6971    }
    7072
     
    9193
    9294    public function generateJWKSignature($input): string {
    93         if(is_array($input) || is_object($input)) {
     95        if(is_array($input) || is_object($input)) {
    9496            $input = wp_json_encode($input);
    9597        }
     98        if($this->api_v3_enabled) {
     99            return self::generateJWKSignatureV3(
     100                $this->fixed_kid_value, $this->fixed_k_value, $input
     101            );
     102        }
     103
    96104        $jwkResource = $this->getJWKResource();
    97105
     
    116124        return $headerEncoded . '.' . $payloadEncoded . '.' . $signatureEncoded;
    117125    }
     126    private static function base64UrlDecode(string $data): string
     127    {
     128        $pad = 4 - (strlen($data) % 4);
     129        if ($pad < 4) $data .= str_repeat('=', $pad);
     130        return base64_decode(strtr($data, '-_', '+/'));
     131    }
     132
     133    public static function generateJWKSignatureV3(string $kid, string $kBase64Url, string $bodyJson): string
     134    {
     135        // JWS header
     136        $header = [
     137            'alg' => 'HS512',
     138            'typ' => 'JWT',
     139            'kid' => $kid
     140        ];
     141
     142        $headerJson   = json_encode($header, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     143        $headerB64    = self::base64UrlEncode($headerJson);
     144
     145        $payloadB64   = self::base64UrlEncode($bodyJson);
     146
     147        $signingInput = $headerB64 . '.' . $payloadB64;
     148
     149        $keyBytes     = self::base64UrlDecode($kBase64Url);
     150
     151        $signature    = hash_hmac('sha512', $signingInput, $keyBytes, true);
     152        $signatureB64 = self::base64UrlEncode($signature);
     153
     154        return $headerB64 . '.' . $payloadB64 . '.' . $signatureB64;
     155    }
    118156
    119157}
  • tami-payment/trunk/lib/Requests/GetInstallmentInfoRequest.php

    r3229701 r3377481  
    2626                include TAMI_PLUGIN_PATH . '/lib/HashGenerator.php';
    2727
    28             $HashGenerator = new HashGenerator($merchantId,$terminalId,$secretKey, $fixedKidValue, $fixedKValue);
    29             $hash = $HashGenerator->generateJWKSignature($requestBody);
     28            $HashGenerator = new HashGenerator($merchantId,$terminalId,$secretKey, $fixedKidValue, $fixedKValue);
     29            $hash = $HashGenerator->generateJWKSignature($requestBody);
    3030
    31             $this->setSecurityHash($hash);
     31            $this->setSecurityHash($hash);
    3232        }
    3333
  • tami-payment/trunk/lib/TamiPaymentClient.php

    r3368346 r3377481  
    1414
    1515class TamiPaymentClient {
     16
     17    const FIXED_KID_VALUE = '00ff6ea8-3511-4d04-946c-ba569208306f';
     18    const FIXED_K_VALUE = '87919a8f-957b-427b-ae12-167622ab52b5';
     19
    1620    private ?string $merchantId;
    1721    private ?string $terminalId;
    1822    private ?string $secret_key;
    19     private ?string $fixed_kid_value = '00ff6ea8-3511-4d04-946c-ba569208306f';
    20     private ?string $fixed_k_value = '87919a8f-957b-427b-ae12-167622ab52b5';
     23    private ?string $fixed_kid_value = self::FIXED_KID_VALUE;
     24    private ?string $fixed_k_value = self::FIXED_K_VALUE;
    2125    private ?string $api_version = 'v2';
    2226    private ?string $method;
  • tami-payment/trunk/readme.txt

    r3368345 r3377481  
    44Requires at least: 5.2
    55Tested up to: 6.8.1
    6 Stable tag: 1.2
     6Stable tag: 1.3
    77Requires PHP: 7.2
    88License: LGPL v3.0
     
    6060= 1.2 =
    6161* Plugin tags updated for Wordpress market warnings.
     62
     63= 1.3 =
     64* API V3 issues fixed.
  • tami-payment/trunk/tami-payment.php

    r3368345 r3377481  
    44 * Plugin URI:              https://www.tami.com.tr/
    55 * Description:             The exact payment method you want for WooCommerce: Tami
    6  * Version:                 1.2
     6 * Version:                 1.3
    77 * Requires at least:       5.2
    88 * Requires PHP:            7.2
Note: See TracChangeset for help on using the changeset viewer.