You can do something like this
class Form extends \Eloquent implements Payable {
/// use PayableTrait;
// you can refractor this to the a PayableTrait
public function payment()
{
return new StripPayments($this);
}
}
class StripePayments implements Payment {
protected $payable;
/**
* Instantiate with Stripe's API Key
*/
public function __construct(Payable $payable)
{
$this->payable = $payable;
$apiKey = Config::get('stripe.secret_key') ?: Config::get('payment::stripe.secret_key');
Stripe::setApiKey($apiKey);
}
/**
* Charge the customer.
*
* @param Payable $model
* @param array $data
* @return mixed|void
*/
public function charge(array $data)
{
try
{
return Stripe_Charge::create([
'amount' => $this->payable->amount,
'currency' => 'usd',
'description' => $data['payment-stripe-email'],
'card' => $data['payment-stripe-token']
]);
} catch(Stripe_CardError $e)
{
dd('Card was declined');
}
}
}
And for your controller something like this
class PaymentApiController extends \BaseController {
public function __construct()
{
}
/**
* Charge the customer.
*
* @return mixed
*/
public function store()
{
$form = Form::create(Input::all());
return $form->payment()->charge(Input::only('token', 'payment-stripe-email', 'payment-stripe-token'));
}
}
Hope this is what you looking for