Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ارور درگاه پاسارگاد #208

Open
babininja opened this issue Dec 7, 2019 · 5 comments
Open

ارور درگاه پاسارگاد #208

babininja opened this issue Dec 7, 2019 · 5 comments

Comments

@babininja
Copy link

وقتی میخام به درگاه پاسارگاد متصل بشم این ارور رو میده

"Declaration of Larabookir\Gateway\Pasargad\Pasargad::ready($payment_id, $callback_url) must be compatible with Larabookir\Gateway\PortInterface::ready()"

@arsiiixxx
Copy link

@babininja baraye in moshkel rah hali peyda kardid ???

@babininja
Copy link
Author

خودم کلاس PortInterface رو اکستند کردم و متد ردیش رو تغییر دادم

@meysam1366
Copy link

سلام
دوست عزیز میشه راه حلش رو هم به ما بگید؟

@babininja
Copy link
Author

اول یه کلاس بسازسد با نام Pasargad
به شکل زیر

<?php

namespace App\Services;


use Illuminate\Support\Facades\Input;
use Larabookir\Gateway\Enum;
use Larabookir\Gateway\Parsian\ParsianErrorException;
use Larabookir\Gateway\Pasargad\Parser;
use Larabookir\Gateway\Pasargad\PasargadErrorException;
use Larabookir\Gateway\Pasargad\RSAKeyType;
use Larabookir\Gateway\Pasargad\RSAProcessor;
use Larabookir\Gateway\PortAbstract;
use Larabookir\Gateway\PortInterface;

class Pasargad extends PortAbstract implements PortInterface
{
    /**
     * {@inheritdoc}
     */
    public function ready()
    {
        $this->sendPayRequest();

        return $this;
    }

    /**
     * Send pay request to parsian gateway
     *
     * @param null $payment_id
     * @param null $callback_url
     * @return bool
     */
    protected function sendPayRequest($payment_id = null, $callback_url = null)
    {
        $this->newTransaction();
    }

    /**
     * Url of parsian gateway web service
     *
     * @var string
     */

    protected $checkTransactionUrl = 'https://pep.shaparak.ir/CheckTransactionResult.aspx';
    protected $verifyUrl = 'https://pep.shaparak.ir/VerifyPayment.aspx';
    protected $refundUrl = 'https://pep.shaparak.ir/doRefund.aspx';

    /**
     * Address of gate for redirect
     *
     * @var string
     */
    protected $gateUrl = 'https://pep.shaparak.ir/gateway.aspx';

    /**
     * {@inheritdoc}
     */
    public function set($amount)
    {
        $this->amount = intval($amount);
        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function redirect()
    {

        $processor = new RSAProcessor("کلید عمومی را اینجا کپی کنید",RSAKeyType::XMLString);

        $url = $this->gateUrl;
        $redirectUrl = url($this->getCallback());
        $invoiceNumber = $this->transactionId();
        $amount = $this->amount;
        $terminalCode = $this->config->get('gateway.pasargad.terminalId');
        $merchantCode = $this->config->get('gateway.pasargad.merchantId');
        $timeStamp = date("Y/m/d H:i:s");
        $invoiceDate = date("Y/m/d H:i:s");
        $action = 1003;
        $data = "#" . $merchantCode . "#" . $terminalCode . "#" . $invoiceNumber .
            "#" . $invoiceDate . "#" . $amount . "#" . $redirectUrl . "#" . $action .
            "#" . $timeStamp . "#";
        $data = sha1($data, true);
        $data = $processor->sign($data); // امضاي ديجيتال
        $sign = base64_encode($data); // base64_encode

        return view('gateway::pasargad-redirector')->with(compact('url', 'redirectUrl', 'invoiceNumber', 'invoiceDate', 'amount', 'terminalCode', 'merchantCode', 'timeStamp', 'action', 'sign'));
    }

    /**
     * {@inheritdoc}
     */
    public function verify($transaction)
    {
        parent::verify($transaction);

        $this->verifyPayment();

        return $this;
    }

    /**
     * Sets callback url
     * @param $url
     * @return $this|string
     */
    function setCallback($url)
    {
        $this->callbackUrl = $url;
        return $this;
    }

    /**
     * Gets callback url
     * @return string
     */
    function getCallback()
    {
        if (!$this->callbackUrl)
            $this->callbackUrl = $this->config->get('gateway.pasargad.callback-url');

        return $this->callbackUrl;
    }


    /**
     * Verify payment
     *
     * @throws ParsianErrorException
     */
    protected function verifyPayment()
    {
        $fields = array(
            'invoiceUID' => Input::get('tref'),
        );

        $result = Parser::post2https($fields, $this->checkTransactionUrl);
        $array = Parser::makeXMLTree($result);
        $verifyResult = $this->callVerifyPayment($array);
        $array['result'] = $verifyResult['result'] ?? false;


        if ($array['result'] != "True") {
            $this->newLog(-1, Enum::TRANSACTION_FAILED_TEXT);
            $this->transactionFailed();
            throw new PasargadErrorException(Enum::TRANSACTION_FAILED_TEXT, -1);
        }

        $this->refId = $array['transactionReferenceID'];
        $this->transactionSetRefId();

        $this->trackingCode = $array['traceNumber'];
        $this->transactionSucceed();
        $this->newLog($array['result'], Enum::TRANSACTION_SUCCEED_TEXT);
    }

    /**
     * @param $data
     * @return array
     */
    protected function callVerifyPayment($data)
    {
        $processor = new RSAProcessor($this->config->get('gateway.pasargad.certificate-path'), RSAKeyType::XMLFile);
        $merchantCode = $this->config->get('gateway.pasargad.merchantId');
        $terminalCode = $this->config->get('gateway.pasargad.terminalId');
        $invoiceNumber = $data['invoiceNumber'];
        $invoiceDate = $data['invoiceDate'];
        $timeStamp = date("Y/m/d H:i:s");
        $amount = $data['amount'];
        $signData = "#" . $merchantCode . "#" . $terminalCode . "#" . $invoiceNumber . "#" . $invoiceDate . "#" . $amount . "#" . $timeStamp . "#";
        $signDataSha1 = sha1($signData, true);
        $tempSign = $processor->sign($signDataSha1);
        $sign = base64_encode($tempSign);

        $body = [
            'merchantCode' => $merchantCode,
            'terminalCode' => $terminalCode,
            'invoiceNumber' => $invoiceNumber,
            'invoiceDate' => $invoiceDate,
            'amount' => $amount,
            'timeStamp' => $timeStamp,
            'sign' => $sign
        ];


        return $this->convertXMLtoArray(Parser::post2https($body, $this->verifyUrl));
    }

    /**
     * @param string $xmlString
     * @return array
     */
    private function convertXMLtoArray($xmlString)
    {
        $xml = simplexml_load_string($xmlString, "SimpleXMLElement", LIBXML_NOCDATA);
        $json = json_encode($xml);

        return json_decode($json,True);
    }

}

بعد یه کلاس با نام Gateway
به صورت زیر

<?php

namespace App\Services;

use Larabookir\Gateway\Asanpardakht\Asanpardakht;
use Larabookir\Gateway\Enum;
use Larabookir\Gateway\Exceptions\PortNotFoundException;
use Larabookir\Gateway\GatewayResolver;
use Larabookir\Gateway\Mellat\Mellat;
use Larabookir\Gateway\Parsian\Parsian;
use Larabookir\Gateway\Payir\Payir;
use Larabookir\Gateway\Paypal\Paypal;
use Larabookir\Gateway\Sadad\Sadad;
use Larabookir\Gateway\Saman\Saman;
use Larabookir\Gateway\Zarinpal\Zarinpal;

class Gateway extends GatewayResolver
{
    /**
     * Create new object from port class
     *
     * @param mixed $port
     * @return $this
     * @throws PortNotFoundException
     */
    function make($port)
    {
        if ($port InstanceOf Mellat) {
            $name = Enum::MELLAT;
        } elseif ($port InstanceOf Parsian) {
            $name = Enum::PARSIAN;
        } elseif ($port InstanceOf PASARGAD ) {// در این قسمت کلاسی که بالاتر ایجاد کردید رو بزارید
            $name = Enum::PASARGAD;
        } elseif ($port InstanceOf Saman) {
            $name = Enum::SAMAN;
        } elseif ($port InstanceOf Zarinpal) {
            $name = Enum::ZARINPAL;
        } elseif ($port InstanceOf Sadad) {
            $name = Enum::SADAD;
        } elseif ($port InstanceOf Asanpardakht) {
            $name = Enum::ASANPARDAKHT;
        } elseif ($port InstanceOf Paypal) {
            $name = Enum::PAYPAL;
        } elseif ($port InstanceOf Payir) {
            $name = Enum::PAYIR;
        }  elseif(in_array(strtoupper($port),$this->getSupportedPorts())){
            $port=ucfirst(strtolower($port));
            $name=strtoupper($port);
            $class=__NAMESPACE__.'\\'.$port.'\\'.$port;
            $port=new $class;
        } else
            throw new PortNotFoundException;

        $this->port = $port;
        $this->port->setConfig($this->config); // injects config
        $this->port->setPortName($name); // injects config
        $this->port->boot();

        return $this;
    }
}


بعد اینجورری کالش کنید

$gateway = new Gateway();//فایل گیت وی جدید
$gateway = $gateway->make(new Pasargad());//فیل پاسارگاد جدید

$gateway->price(1000)->ready();
return $gateway->redirect();

@sama20
Copy link

sama20 commented Oct 25, 2020

سلام
برای من هم نسخه 3.4 همین مشکل رو داشتم
پوشه
scr/pasargad
از نسخه 3.3 همین پروژه رو جایگزین کردم مشکل رفع شد.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants