İçeriğe geç
Tüm kodlar

ER3NSHOP

Kurulum sihirbazlı online mağaza sistemi

68 satır · 3 KBHamİndir
<?php

// Shopier: müşteri imzalı bir formla Shopier ödeme sayfasına gönderilir.
// Sonuç, Shopier panelindeki "Geri dönüş URL" adresine (odeme-sonuc?saglayici=shopier) tarayıcıyla POST edilir.
function gateway_shopier_start($order, $payment)
{
    [$first, $last] = split_name($order['name']);
    $random = (string) random_int(100000, 999999);
    $total = number_format((float) $order['total'], 2, '.', '');
    $currency = 0; // 0 = TL
    $signature = base64_encode(hash_hmac('sha256', $random . $payment['reference'] . $total . $currency, setting('shopier_secret'), true));
    $names = array_column(payment_basket($order), 'name');

    return ['type' => 'form', 'url' => 'https://www.shopier.com/ShowProduct/api_pay4.php', 'fields' => [
        'API_key'           => setting('shopier_api_key'),
        'website_index'     => setting('shopier_website_index', '1'),
        'platform_order_id' => $payment['reference'],
        'product_name'      => mb_substr(implode(', ', $names), 0, 200),
        'product_type'      => 0,
        'buyer_name'        => $first,
        'buyer_surname'     => $last,
        'buyer_email'       => $order['email'],
        'buyer_account_age' => 0,
        'buyer_id_nr'       => $order['customer_id'] ?: 0,
        'buyer_phone'       => phone_digits($order['phone']),
        'billing_address'   => $order['address'],
        'billing_city'      => $order['city'],
        'billing_country'   => 'Türkiye',
        'billing_postcode'  => '',
        'shipping_address'  => $order['address'],
        'shipping_city'     => $order['city'],
        'shipping_country'  => 'Türkiye',
        'shipping_postcode' => '',
        'total_order_value' => $total,
        'currency'          => $currency,
        'platform'          => 0,
        'is_in_frame'       => 0,
        'current_language'  => 0,
        'modul_version'     => '1.0.4',
        'random_nr'         => $random,
        'signature'         => $signature,
        'callback'          => url('odeme-sonuc?saglayici=shopier'),
    ]];
}

// Shopier dönüşü: imzayı doğrular, ödeme kaydını günceller ve kaydı döner.
function gateway_shopier_callback()
{
    $reference = post('platform_order_id', '');
    $payment = payment_by_reference($reference);
    if (!$payment || $payment['provider'] !== 'shopier') {
        return null;
    }

    $expected = hash_hmac('sha256', post('random_nr', '') . $reference, setting('shopier_secret'), true);
    $given = base64_decode((string) post('signature', ''), true);
    $raw = ['status' => post('status'), 'payment_id' => post('payment_id'), 'installment' => post('installment')];

    if ($given === false || !hash_equals($expected, $given)) {
        payment_failed($payment, 'Shopier imzası doğrulanamadı.', $raw);
        return $payment;
    }

    strtolower((string) post('status')) === 'success'
        ? payment_paid($payment, post('payment_id', $reference), (int) post('installment', 1), $raw)
        : payment_failed($payment, post('error_message', 'Ödeme tamamlanmadı.'), $raw);
    return $payment;
}

Lisans bilgisi projenin LICENSE dosyasında.