<?php

namespace App\Services;

use App\Models\PaymentGetwayCredential;

class PaymentGetwayCredentialService
{
    public static function store($request)
    {
        $paymentgetway = new PaymentGetwayCredential();
        $paymentgetway->reseller_id = $request->reseller_id;
        $paymentgetway->getway_name = $request->getway_name;
        $paymentgetway->appkey_publickey = $request->appkey_publickey;
        $paymentgetway->secretkey_privatekey = $request->secretkey_privatekey;
        $paymentgetway->username_merchantid = $request->username_merchantid;
        $paymentgetway->password_merchantnumber = $request->password_merchantnumber;
        $paymentgetway->base_url = $request->base_url;
        $paymentgetway->callback_url = $request->callback_url;
        $paymentgetway->payer_reference = $request->payer_reference ?? '019';
        $paymentgetway->save();

        return $paymentgetway;
    }

    public static function update($request, $id)
    {
        $paymentgetway = PaymentGetwayCredential::find($id);
        $paymentgetway->reseller_id = $request->reseller_id;
        $paymentgetway->getway_name = $request->getway_name;
        $paymentgetway->appkey_publickey = $request->appkey_publickey;
        $paymentgetway->secretkey_privatekey = $request->secretkey_privatekey;
        $paymentgetway->username_merchantid = $request->username_merchantid;
        $paymentgetway->password_merchantnumber = $request->password_merchantnumber;
        $paymentgetway->base_url = $request->base_url;
        $paymentgetway->callback_url = $request->callback_url;
        $paymentgetway->payer_reference = $request->payer_reference ?? '019';
        $paymentgetway->save();

        return $paymentgetway;
    }

}
