Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Custom payment method failed

    General Discussion
    2
    3
    222
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ?
      A Former User last edited by

      Hi, I tried a guide for a custom payment.
      First I created the package, I created all the http files, routes and repository
      In the Controller I put a confirm class to confirm the payment when I am taken to the sandbox and in the Repository the logic of the payment itself which I call in the OrderRepository

      Controller
       protected $invoiceRepository;
      
          protected $this->orderRepository;
      
          public function __construct(
              OrderRepository $this->orderRepository,
              InvoiceRepository $invoiceRepository
          )
          {
              $this->orderRepository = $this->orderRepository;
      
              $this->invoiceRepository = $invoiceRepository;
          }
      
          public function confirm()
          {
              $response = Mobilpay::response();
              $data = $response->getData();
              Log::info("OrderID: {$data['orderId']} | Response: ".json_encode($data));
              $this->order = Order::where('id', $data['params']['orderId'])->first();
      
              if ($data['objPmNotify']['errorCode'] == 0 && $this->order) {
                  switch ($response->getMessage()) {
                      case 'confirmed_pending': // transaction is pending review. After this is done, a new IPN request will be sent with either confirmation or cancellation
                          $this->order->status_mobilpay = 'confirmed_pending';
                          // $payment->save();
                          //update DB, SET status = "pending"
      
                          break;
                      case 'paid_pending': // transaction is pending review. After this is done, a new IPN request will be sent with either confirmation or cancellation
                          $this->order->status_mobilpay = 'paid_pending';
                          // $payment->save();
                          //update DB, SET status = "pending"
      
                          break;
                      case 'paid': // transaction is pending authorization. After this is done, a new IPN request will be sent with either confirmation or cancellation
                          $this->order->status_mobilpay = 'paid';
                          // $payment->save();
                          //update DB, SET status = "open/preauthorized"
      
                          break;
                      case 'confirmed': // transaction is finalized, the money have been captured from the customer's account
                          $this->order->status_mobilpay = 'confirmed';
                          Mail::to($this->order->billing_email)->send(new Proforma($this->order->id));
                          if (!empty($this->settings->email_orders)) {
                              Mail::to($this->settings->email_orders)->send(new Proforma($this->order->id));
                          }
                          //update DB, SET status = "confirmed/captured"
      
                          break;
                      case 'canceled': // transaction is canceled
                          $this->order->status_mobilpay = 'canceled';
                          // $payment->save();
                          //update DB, SET status = "canceled"
      
                          break;
                      case 'credit': // transaction has been refunded
                          $this->order->status_mobilpay = 'credit';
                          // $payment->save();
                          //update DB, SET status = "refunded"
      
                          break;
                  }
                  $this->order->message_mobilpay = $data['objPmNotify']['errorMessage'];
                  $this->order->error_code_mobilpay = $data['objPmNotify']['errorCode'];
                  $this->order->save();
              } else {
                  if ($this->order) {
                      $this->order->message_mobilpay = $data['objPmNotify']['errorMessage'];
                      $this->order->error_code_mobilpay = $data['objPmNotify']['errorCode'];
                      $this->order->status_mobilpay = 'rejected';
                      $this->order->save();
                  }
              }
          }
      

      Repository

       public function pay(Order $order)
          {
              $mobilpayOrderId = time();
              $order->mobilpay_orderid = $mobilpayOrderId;
              $order->save();
              Mobilpay::setOrderId($mobilpayOrderId)
                  ->setAmount($order->total)
                  ->setAdditionalParams([
                      'orderId' => $order->id,
                  ])
                  ->setBillingAddress([
                      'type' => 1,
                      'firstName' => 'test',
                      'lastName' => 'test',
                      'country' => 'Romania',
                      'county' => 'test',
                      'city' => 'test',
                      'address' => 'test',
                      'email' => 'test',
                      'mobilePhone' => 'test',
                  ])
                  ->setShippingAddress([
                      'firstName' => 'test',
                      'lastName' => 'test',
                      'country' => 'Romania',
      	            'county' => 'test',
      	            'city' => 'test',
                      'address' => 'test',
                      'email' => 'test',
                      'mobilePhone' => 'test',
                  ])
                  ->setDetails('Comanda noua pe platforma '.env('APP_NAME'))
                  ->purchase();
          }
      

      And in OrderRepository before return order I tried this

      $mobilpayRepository = new MobilPayRepository();
              $mobilpayRepository->pay($order);
              return $order;
      

      What could be the problem?
      I don't get errors, I'm just not redirected.

      Can I provide other details?

      1 Reply Last reply Reply Quote 0
      • R
        rahul last edited by

        Hello DaniD

        Please make sure that you have inserted correct credentials for your payment getaway and when a customer is clinking to your payment getaway, it is redirecting properly.

        As you have mentioned that, you are not getting any error, so we need little bit more explanation on this.

        Thanks

        1 Reply Last reply Reply Quote 0
        • ?
          A Former User last edited by

          I do not receive a response when I call mobilpay ($ order)
          Maybe I shouldn't call where the order function is?
          Usually where would a payment function be called when the order is placed?

          1 Reply Last reply Reply Quote 0
          • First post
            Last post