-
Notifications
You must be signed in to change notification settings - Fork 3
Usage
PayableContract
must be implemented by your model, and it must use Payable
trait.
...
use Afbora\IyzipayLaravel\Payable;
use Afbora\IyzipayLaravel\PayableContract;
class User extends Authenticatable implements PayableContract
{
use Notifiable, Payable;
.....
}
After interface and trait setup, now your App\User model is ready to pay for products and subscribe to plans. But iyzico must know about billing information first. So, you can fill billing fields simply like this;
use Afbora\IyzipayLaravel\StorableClasses\Address;
use Afbora\IyzipayLaravel\StorableClasses\BillFields;
$user = factory(\App\User::class)->create();
$user->bill_fields = new BillFields([
'first_name' => 'John,
'last_name' => 'Doe',
'email' => '[email protected]',
'shipping_address' => new Address([
'city' => 'Beşiktaş, İstanbul',
'country' => 'Türkiye',
'address' => 'Mecidiye Mh.'
]),
'billing_address' => new Address([
'city' => 'Beşiktaş, İstanbul',
'country' => 'Türkiye',
'address' => 'Mecidiye Mh.'
]),
'identity_number' => '11111111111',
'mobile_number' => '5555555555'
]);
This process require billing information first, be sure that User has billing information, then you can add credit card for User like below
$user->addCreditCard([
'alias' => 'My Debit',
'number' => '5890040000000016',
'month' => '01'
'year' => '2030',
'holder' => 'John Doe'
]);
For manually charging operation you should have Product
models. With implementing ProductContract
to this models, you must give information about product in these methods below;
use Afbora\IyzipayLaravel\ProductContract;
class Product extends Model implements ProductContract
{
public function getName()
{
// return product name here.
return $this->name;
}
public function getPrice()
{
// return price here
return $this->price;
}
public function getCategory()
{
// return category here
return $this->category;
}
public function getType()
{
// return product type here, for ex;
return BasketItemType::VIRTUAL;
}
}
You can create your plans at app/Providers/AppServiceProvider.php
file's register()
method.
\IyzipayLaravel::plan('aylik-ucretsiz', 'Aylık Ücretsiz');
\IyzipayLaravel::plan('aylik-standart', 'Aylık Standart')->trialDays(15)->price(20);
\IyzipayLaravel::plan('aylik-platinum', 'Aylık Platinum')->trialDays(15)->price(40);
\IyzipayLaravel::plan('yillik-kucuk', 'Yıllık Küçük')->yearly()->price(150);
\IyzipayLaravel::plan('yillik-standart', 'Yıllık Standart')->yearly()->trialDays(15)->price(200);
\IyzipayLaravel::plan('yillik-platinum', 'Yıllık Platinum')->yearly()->trialDays(15)->price(400);
Note: Please be sure that, your identifiers for your plans to be unique.
You can filter your plans with the given methods below;
IyzipayLaravel::plans(); // returns all your plans as Collection.
IyzipayLaravel::monthlyPlans(); // returns all your monthly plans as Collection.
IyzipayLaravel::yearlyPlans(); // returns all your yearly plans as Collection.
IyzipayLaravel::findPlan('aylik-ucretsiz'); // returns Plan with given identifier.
You can subscribe your PayableContract
s to plans with just like this;
$user->subscribe(\IyzipayLaravel::findPlan($id));
To get paid in time be sure that, you already mapped schedule runner to your cron file like this.