billowapp / payfast

Basic Laravel Package For ITN Payments through Payfast
MIT License
27 stars 37 forks source link

Target [Billow\Contracts\PaymentProcessor] is not instantiable. #7

Open venkatavinash opened 6 years ago

venkatavinash commented 6 years ago

Hello,

I have included all as described but I am getting the following when I call the route onto PaymentContoller@confirmPayment

Target [Billow\Contracts\PaymentProcessor] is not instantiable.

/var/www/html/bidtend/bidtend/vendor/laravel/framework/src/Illuminate/Container/Container.php

/**
 * Throw an exception that the concrete is not instantiable.
 *
 * @param  string  $concrete
 * @return void
 *
 * @throws \Illuminate\Contracts\Container\BindingResolutionException
 */
protected function notInstantiable($concrete)
{
    if (! empty($this->buildStack)) {
        $previous = implode(', ', $this->buildStack);

        $message = "Target [$concrete] is not instantiable while building [$previous].";
    } else {
        $message = "Target [$concrete] is not instantiable.";
    }

    throw new BindingResolutionException($message);
}

/**
 * Throw an exception for an unresolvable primitive.
 *
 * @param  \ReflectionParameter  $parameter
 * @return void
 *
 * @throws \Illuminate\Contracts\Container\BindingResolutionException
 */
protected function unresolvablePrimitive(ReflectionParameter $parameter)
{
    $message = "Unresolvable dependency resolving [$parameter] in class {$parameter->getDeclaringClass()->getName()}";

    throw new BindingResolutionException($message);
}

/**
 * Register a new resolving callback.
 *

Arguments "Target [Billow\Contracts\PaymentProcessor] is not instantiable."

any help would be appreciated.

Laravel 5.5 , php 7.0

mikerockett commented 6 years ago

Contracts (that is, PHP interfaces) are not directly instantiable. Would you mind sharing your code for confirmPayment()?

venkatavinash commented 6 years ago

true. i did not checked the code before posting here.

I have changed use Billow\Contracts\PaymentProcessor; to use Billow\Payfast and passed it using public function somthing(Payfast $payfast).

Working fine now.

Is there a need to change the code ? I think so.

mikerockett commented 6 years ago

Something would be going wrong on your side if the contract does not work. The service provider binds the contract to the Payfast class in the service container (which is why the class works when you pull it in directly). I’d still like to find out why binding the contract is not working on your side… I’ve tested on PHP 7.0/7.1 with L5.5, and it all works fine.

venkatavinash commented 6 years ago

I have used the same code which was given in example. public function confirmPayment(PaymentProcessor $payfast) { // Eloqunet example.
$cartTotal = 9999; $order = Order::create([ 'm_payment_id' => '001', // A unique reference for the order. 'amount' => $cartTotal
]);

    // Build up payment Paramaters.
    $payfast->setBuyer('first name', 'last name', 'email');
    $payfast->setAmount($order->amount);
    $payfast->setItem('item-title', 'item-description');
    $payfast->setMerchantReference($order->m_payment_id);

    // Return the payment form.
    return $payfast->paymentForm('Place Order');
}

But I have passed now Request $request and used Payfast $payfast which seems to be working.

Is it not right way to implement?