Payum / PayumLaravelPackage

Payum offers everything you need to work with payments. From simplest use cases to very advanced ones.
https://payum.forma-pro.com/
MIT License
122 stars 38 forks source link

GetHumanStatus{model: ArrayObject} is not supported #40

Closed krinkel closed 8 years ago

krinkel commented 8 years ago

I want to use the PayumLaravelPackage with Payum/Payex , I followed the documentation here and tried to do a purchase, every thing done well, But when I am redirected to: http://project.dev:8000/en/payment/done/PMFgtu2IOoEWUTRZhF95slwNw95mDW5B6cF826J-fi8

, an error is triggered:

Request GetHumanStatus{model: ArrayObject} is not supported. Make sure the gateway supports the requests and there is an action which supports this request (The method returns true). There may be a bug, so look for a related issue on the issue tracker.

,, my AppServiceProvider is:

public function register()
    {
        $this->app->resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
            $payumBuilder
                // this method registers filesystem storages, consider to change them to something more
                // sophisticated, like eloquent storage
                ->addDefaultStorages()

                ->addGateway('payex', [
                    'factory' => 'payex',
                    'account_number' => 'my account number',
                    'encryption_key' => 'my key',
                    'sandbox' => true
                ]);
        });

    }

and my Payment Controller :


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Payum\Core\Request\GetHumanStatus;
use Payum\LaravelPackage\Controller\PayumController;

class PaymentController extends PayumController
{

    public function done($payum_token, Request $request)
    {
        $request->attributes->set('payum_token', $payum_token);

        $token = $this->getPayum()->getHttpRequestVerifier()->verify($request);
        $gateway = $this->getPayum()->getGateway($token->getGatewayName());

        $gateway->execute($status = new GetHumanStatus($token));

        return response([
            'status' => $status->getValue(),
            'details' => iterator_to_array($status->getFirstModel())
        ]);
    }

    public function captureDoneAction(Request $request)
    {
        $token = $this->get('payum')->getHttpRequestVerifier()->verify($request);

        $identity = $token->getDetails();
        $model = $this->get('payum')->getStorage($identity->getClass())->find($identity);

        $gateway = $this->get('payum')->getGateway($token->getGatewayName());

        // you can invalidate the token. The url could not be requested any more.
        // $this->get('payum')->getHttpRequestVerifier()->invalidate($token);

        // Once you have token you can get the model from the storage directly.
        //$identity = $token->getDetails();
        //$details = $payum->getStorage($identity->getClass())->find($identity);

        // or Payum can fetch the model for you while executing a request (Preferred).
        $gateway->execute($status = new GetHumanStatus($token));
        $details = $status->getFirstModel();

        // you have order and payment status
        // so you can do whatever you want for example you can just print status and payment details.

        return new JsonResponse(array(
            'status' => $status->getValue(),
            'details' => iterator_to_array($details),
        ));
    }
}

and that is my Payex Controller:

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Http\Request;
use Payum\Payex\Api\OrderApi;
use Payum\LaravelPackage\Controller\PayumController;
use App\Http\Controllers\OrdersController as OrdersCart;

class PayexController extends PayumController
{

    public $cart;

    public function __construct(OrdersCart $ordersCart)
    {
        $this->cart = $ordersCart;
    }

    public function preparePayex( Request $request)
    {
        $storage = $this->getPayum()->getStorage('Payum\Core\Model\ArrayObject');

        $details = $storage->create();
        $details['price'] = $this->cart->updateCartTotalPrice($this->cart->currentCart);
        $details['priceArgList'] = '';
        $details['vat'] = 0;
        $details['currency'] = 'SEK';
        $details['orderId'] = $this->cart->currentCart;
        $details['productNumber'] = $this->cart->currentCart;
        $details['purchaseOperation'] = OrderApi::PURCHASEOPERATION_AUTHORIZATION;
        $details['view'] = OrderApi::VIEW_CREDITCARD;
        $details['description'] = '';
        $details['clientIPAddress'] = $request->getClientIp();
        $details['clientIdentifier'] = '';
        $details['additionalValues'] = '';
        $details['agreementRef'] = '';
        $details['clientLanguage'] = 'en-US';

        $storage->update($details);

        $captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken('payex', $details, 'payment_done');

        $details['returnurl'] = $captureToken->getTargetUrl();
        $details['cancelurl'] = $captureToken->getTargetUrl();
        $storage->update($details);

        return redirect($captureToken->getTargetUrl());
    }

}

and i use laravel 5.2 This error is caused me a lot of boredom, so please some one help.

krinkel commented 8 years ago

now when i visit prepare page: http://project.dev:8000/en/payment/payex/prepare it is redirect me directly to: http://project.dev:8000/en/payment/done/6ZSqW2986XZZGKlvuImyuA2QV38MsQlj9Br6wjGCK4A with the same error, without fill any visa information. it same that the service cached my request and get the same response, i think now i can’t test solutions correctly. Someone could help me with the first main bug?

makasim commented 8 years ago

The code you posted looks good, at least at a quick glance. so it may be a bug in the payex extension.

krinkel commented 8 years ago

@makasim Is it expected to fix it within a short period? and very thanks for help

makasim commented 8 years ago

I do not have some spare time on it right now.

makasim commented 8 years ago

I created an issue on payum/payum repo

krinkel commented 8 years ago

as a reference, i found https://github.com/recca0120/laravel-payum repository, developed from payum/payum package, but with more flexibility to work with laravel, and it work with me without this bug. and very thanks for help @makasim