Skip to content
Mehmet Aydin Bahadir edited this page Apr 7, 2017 · 1 revision

Getting your application ready to sale

Step 1- Payable Implementation

PayableContract must be implemented by your model, and it must use Payable trait.

...
use Iyzico\IyzipayLaravel\Payable;
use Iyzico\IyzipayLaravel\PayableContract;

class User extends Authenticatable implements PayableContract
{
    use Notifiable, Payable;
    
    .....
}

Step 2- Fill billing informations for 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 Iyzico\IyzipayLaravel\StorableClasses\Address;
use Iyzico\IyzipayLaravel\StorableClasses\BillFields;

$user = factory(\App\User::class)->create();
$user->bill_fields = new BillFields([
    'first_name'       => 'Mehmet Aydın',
    'last_name'        => 'Bahadır',
    'email'            => 'mehmet.aydin.bahadir@gmail.com',
    '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'  => '12345678901',
    'mobile_number'    => '05555555555'
]);

Step 3- Storing credit card on iyzipay for your payable model

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'  => 'asd', 
    'number' => '5526080000000006',
    'month'  => '01'
    'year'   => '2030',
    'holder' => 'Mehmet Aydın Bahadır'
]);

Single Charges

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 Iyzico\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;
    }
}

Subscriptions

Step 1- Creating Plans

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.

Step 2- Subscription to plans

You can subscribe your PayableContracts 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.

Clone this wiki locally
You can’t perform that action at this time.