In Laravel versions >= 5.5 the service provider and facade will automatically be registered and enabled.
In older versions of the framework just add the package service provider and facade in 'config/app.php' file:
'providers' => [
...
'StriderTech\PeachPayments\PeachPaymentsServiceProvider',
]
'aliases' => [
...
'PeachPayments' => 'StriderTech\PeachPayments\Facade\PeachPaymentsFacade',
]
Add package migrations and vendors with commands:
php artisan vendor:publish --provider="StriderTech\PeachPayments\PeachPaymentsServiceProvider"
After publishing of vendors edit config file: app/config/peachpayments.php
and run migrations:
php artisan migrate
Add the Billable trait to your model definition. This trait provides various methods to allow you to perform common tasks, such as registration cards, creating payments, applying coupons, and updating credit card information:
use StriderTech\PeachPayments\Billable;
class User extends Authenticatable
{
use Billable;
}
$user = Auth::user();
$card = new PaymentCard();
$card->setCardBrand(CardBrand::MASTERCARD)
->setCardNumber('5454545454545454')
->setCardHolder('Jane Jones')
->setCardExpiryMonth('05')
->setCardExpiryYear('2020')
->setCardCvv('123');
$user->storeCard($card);
$user->storeCardByToken($token);
$cards = $user->cards;
$paymentCard = PaymentCard::find($id);
$payment = new Payment();
$payment->fromPaymentCard($paymentCard);
$payment->setCurrency('ZAR')
->setAmount(90.9);
$user->pay($payment);
$payments = $user->payments;
$user->deleteCardByToken($token);