روز برنامه‌نویس مبارک 🤩🎉 از هدایای روز برنامه‌نویس جا نمونی ⌛
۰ ثانیه
۰ دقیقه
۰ ساعت
۲ روح الله طالبیان
مواجه شدن با error بعد از در انتظار پرداخت
جامعه پی اچ پی ایجاد شده در ۰۵ دی ۱۴۰۰

با سلام و خسته نباشید من با این error برخورد کردم نمی‌دونم مشکل از کجاست؟

ErrorCall to undefined method App\\Services\\Payment\\Requests\\IDPayVerifyRequest::getAmount()

http://127.0.0.1:8000/payment/callback

C:\\xampp\\htdocs\\dashboard\\gallery\\app\\Services\\Payment\\Providers\\IDPayProvider.php:16

که خط 16 این هست -> 'amount' => $this->request->getAmount(),

و صفحه کامل IDPayProvider.php

namespace App\\Services\\Payment\\Providers;
 
use App\\Services\\Payment\\Contracts\\PayableInterface;
use App\\Services\\Payment\\Contracts\\Verifaibleinterface;
use App\\Services\\Payment\\Contracts\\AbstractProviderInterface;
class IDPayProvider extends AbstractProviderInterface implements PayableInterface,Verifaibleinterface
{
    private $statusOk=100;
    public function pay()
    {
        $params = array(
            'order_id' =>$this->request->getOrderId(),
            'amount' => $this->request->getAmount(),
            'name' => $this->request->getUser()->name,
            'phone' => $this->request->getUser()->mobile,
            'mail' => $this->request->getUser()->email,
            'callback' => route('payment.callback'),
          );
          
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, 'https://api.idpay.ir/v1.1/payment');
          curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
          curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            'X-API-KEY:'. $this->request->getApiKey().'',
            'X-SANDBOX: 1'
          ));
          
          $result = curl_exec($ch);
          curl_close($ch);
          
          $result = json_decode($result,true);
         if(isset($result['error_code']))
         {
           throw new \\InvalidArgumentException($result['error_message']);
         }
          return redirect()->away($result['link']);
    }
    public function verify()
    {
      $params = array(
        'id' => $this->request->getId(),
        'order_id' => $this->request->getOrderId(),
      );
      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, 'https://api.idpay.ir/v1.1/payment/verify');
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'X-API-KEY: '. $this->request->getApiKey().'',
        'X-SANDBOX: 1',
      ));
      
      $result = curl_exec($ch);
      curl_close($ch);
      
      $result=json_decode($result,true);
      if(isset($result['error_code']))
      {
        return [
          'status'=>false,
          'statusCode'=>$result['error_code'],
          'msg'=>$result['error_message'],
        ];
      }
      
      if($result['status']==$this->statusOk)
      {
        return [
          'status'=>true,
          'statusCode'=>$result['status'],
          'data'=>$result,
        ];
      }
      return [
        'status'=>true,
        'statusCode'=>$result['status'],
        'data'=>$result,
      ];
    }
    
}

و صفحه کامل IDPayRequest

namespace App\\Services\\Payment\\Requests;

 

use App\\Services\\Payment\\Contracts\\RequestInterface;

class IDPayRequest implements RequestInterface

{

    private $user;

    private $amount;

    private $orderId;

    private $apiKey;

   

    public function __construct(array $data)

    {

        $this->user=$data['user'];

        $this->amount=$data['amount'];

        $this->orderId=$data['order_id'];

        $this->apiKey=$data['apiKey'];

       

    }

    public function getUser()

    {

        return $this->user;

    }

    public function getAmount()

    {

        return $this->amount * 10;

    }

    public function getOrderId()

    {

        return $this->orderId;

    }

    public function getApiKey()

    {

        return $this->apiKey;

    }

}

و صفحه کامل IDPayVerifyRequest

namespace App\\Services\\Payment\\Requests;

use App\\Services\\Payment\\Contracts\\RequestInterface;

 

class IDPayVerifyRequest implements RequestInterface

{

    private $id;

    private $orderId;

    private $apiKey;

   

   

    public function __construct(array $data)

    {

        $this->id=$data['id'];

        $this->orderId=$data['orderId'];

        $this->apiKey=$data['apiKey'];

       

    }

 

    public function getId()

    {

        return $this->id;

    }

   

    public function getOrderId()

    {

        return $this->orderId;

    }

    public function getApiKey()

    {

        return $this->apiKey;

    }

   

   

   

}

ممنون میشم راهنمایی ام کنید

سلام و احترام

ErrorCall to undefined method App\\Services\\Payment\\Requests\\IDPayVerifyRequest::getAmount()

این خطا میگه که شما متد getAmount رو اصلا توی کلاس IDPayVerifyRequest تعریف نکردید، یه بار بررسی کنید و اطلاع بدید


امیر صالحی ۰۷ دی ۱۴۰۰، ۰۷:۴۵

درود مجدد بر آقای صالحی عزیز ،

شما در ویدیوفرموده بودید که در کلاس IDPayVerifyRequest دیگر نیازی به getAmount نداریم حالا با گذاشتنش با خطایی دیگر روبرو میشم که کاملا از این تناقض گیج شدم

ErrorExceptionUndefined array key "amount"

http://127.0.0.1:8000/payment/callback

C:\\xampp\\htdocs\\dashboard\\gallery\\app\\Services\\Payment\\Requests\\IDPayVerifyRequest.php:20

use App\\Services\\Payment\\Contracts\\RequestInterface;
 
class IDPayVerifyRequest implements RequestInterface
{
    private $id;
    private $orderId;
    private $apiKey;
    private $amount;
 
 
    public function __construct(array $data)
    {
        $this->id=$data['id'];
        $this->orderId=$data['orderId'];
        $this->apiKey=$data['apiKey'];
        $this->amount=$data['amount'];
 
    }
 
    public function getId()
    {
        return $this->id;
    }
 
    public function getAmount()
    {
        return $this->amount * 10;
    }
 
    public function getOrderId()
    {

بازم ممنون میشم از حس توجه تون

روح الله طالبیان ۰۷ دی ۱۴۰۰، ۱۵:۵۷