Skip to content

Commit b31e5ee

Browse files
author
mostafa
committed
lara stripe refactoring
1 parent 18b70f8 commit b31e5ee

10 files changed

+190
-16
lines changed

src/Facades/LStripeBalance.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
/**
66
* @author @code4mk <[email protected]>
7-
* @author @0devco <with@0dev.co>
8-
* @copyright 0dev.co (https://0dev.co)
7+
* @author @kawsarsoft <with@kawsarsoft.com>
8+
* @copyright Kawsar Soft. (http://kawsarsoft.com)
99
*/
1010

1111
use Illuminate\Support\Facades\Facade;

src/Facades/LStripeCharge.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
/**
66
* @author @code4mk <[email protected]>
7-
* @author @0devco <with@0dev.co>
8-
* @copyright 0dev.co (https://0dev.co)
7+
* @author @kawsarsoft <with@kawsarsoft.com>
8+
* @copyright Kawsar Soft. (http://kawsarsoft.com)
99
*/
1010

1111
use Illuminate\Support\Facades\Facade;

src/Facades/LStripeCheckout.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
/**
66
* @author @code4mk <[email protected]>
7-
* @author @0devco <with@0dev.co>
8-
* @copyright 0dev.co (https://0dev.co)
7+
* @author @kawsarsoft <with@kawsarsoft.com>
8+
* @copyright Kawsar Soft. (http://kawsarsoft.com)
99
*/
1010

1111
use Illuminate\Support\Facades\Facade;

src/Facades/LStripeCoupon.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Code4mk\LaraStripe\Facades;
4+
5+
/**
6+
* @author @code4mk <[email protected]>
7+
* @author @kawsarsoft <[email protected]>
8+
* @copyright Kawsar Soft. (http://kawsarsoft.com)
9+
*/
10+
11+
use Illuminate\Support\Facades\Facade;
12+
13+
class LStripeCoupon extends Facade
14+
{
15+
/**
16+
* Get the registered name of the component.
17+
*
18+
* @return string
19+
*/
20+
protected static function getFacadeAccessor()
21+
{
22+
return 'laraStripeCoupon';
23+
}
24+
}

src/Facades/LStripeCustomer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
/**
66
* @author @code4mk <[email protected]>
7-
* @author @0devco <with@0dev.co>
8-
* @copyright 0dev.co (https://0dev.co)
7+
* @author @kawsarsoft <with@kawsarsoft.com>
8+
* @copyright Kawsar Soft. (http://kawsarsoft.com)
99
*/
1010

1111
use Illuminate\Support\Facades\Facade;

src/Facades/LStripePlan.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Code4mk\LaraStripe\Facades;
4+
5+
/**
6+
* @author @code4mk <[email protected]>
7+
* @author @kawsarsoft <[email protected]>
8+
* @copyright Kawsar Soft. (http://kawsarsoft.com)
9+
*/
10+
11+
use Illuminate\Support\Facades\Facade;
12+
13+
class LStripePlan extends Facade
14+
{
15+
/**
16+
* Get the registered name of the component.
17+
*
18+
* @return string
19+
*/
20+
protected static function getFacadeAccessor()
21+
{
22+
return 'laraStripePlan';
23+
}
24+
}

src/Facades/LStripeSubscription.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Code4mk\LaraStripe\Facades;
4+
5+
/**
6+
* @author @code4mk <[email protected]>
7+
* @author @kawsarsoft <[email protected]>
8+
* @copyright Kawsar Soft. (http://kawsarsoft.com)
9+
*/
10+
11+
use Illuminate\Support\Facades\Facade;
12+
13+
class LStripeSubscription extends Facade
14+
{
15+
/**
16+
* Get the registered name of the component.
17+
*
18+
* @return string
19+
*/
20+
protected static function getFacadeAccessor()
21+
{
22+
return 'laraStripeSubscription';
23+
}
24+
}

src/LaraStripeServiceProvider.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Code4mk\LaraStripe\StripeCheckout;
1515
use Code4mk\LaraStripe\StripeBalance;
1616
use Code4mk\LaraStripe\StripeCustomer;
17+
use Code4mk\LaraStripe\StripePlans;
18+
use Code4mk\LaraStripe\StripeCoupon;
19+
use Code4mk\LaraStripe\StripeSubscription;
1720

1821
class LaraStripeServiceProvider extends ServiceProvider
1922
{
@@ -35,6 +38,10 @@ public function boot()
3538
AliasLoader::getInstance()->alias('LaraStripeCheckout', 'Code4mk\LaraStripe\Facades\LStripeCheckout');
3639
AliasLoader::getInstance()->alias('LaraStripeBalance', 'Code4mk\LaraStripe\Facades\LStripeBalance');
3740
AliasLoader::getInstance()->alias('LaraStripeCustomer', 'Code4mk\LaraStripe\Facades\LStripeCustomer');
41+
AliasLoader::getInstance()->alias('LaraStripeCoupon', 'Code4mk\LaraStripe\Facades\LStripeCoupon');
42+
AliasLoader::getInstance()->alias('LaraStripePlan', 'Code4mk\LaraStripe\Facades\LStripePlan');
43+
AliasLoader::getInstance()->alias('LaraStripeSubs', 'Code4mk\LaraStripe\Facades\LStripeSubscription');
44+
3845
}
3946

4047
/**
@@ -60,5 +67,17 @@ public function register()
6067
return new StripeCustomer;
6168
});
6269

70+
$this->app->bind('laraStripeCoupon', function () {
71+
return new StripeCoupon;
72+
});
73+
74+
$this->app->bind('laraStripePlan', function () {
75+
return new StripePlans;
76+
});
77+
78+
$this->app->bind('laraStripeSubscription', function () {
79+
return new StripeSubscription;
80+
});
81+
6382
}
6483
}

src/StripeCoupon.php

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,62 @@
77
* @copyright Kawsar Soft. (http://kawsarsoft.com)
88
*/
99

10-
// https://stripe.com/docs/api/coupons
11-
10+
use Stripe\Stripe;
11+
use Stripe\Coupon;
12+
use Config;
13+
14+
/**
15+
* Coupon class
16+
* @source https://stripe.com/docs/api/coupons
17+
*/
1218
class StripeCoupon
1319
{
1420
/**
1521
* Secret key
1622
* @var string
1723
*/
1824
private $secretKey;
25+
1926
/**
20-
* Customer all data after create
21-
* @var object
27+
* Currency when coupon amount is fixed
28+
* @var string
2229
*/
2330
private $currency;
2431

32+
/**
33+
* Coupon amount
34+
* @var integer|float
35+
*/
2536
private $amount;
37+
38+
/**
39+
* Coupon amount type
40+
* @var string per or fixed
41+
*/
2642
private $type;
43+
44+
/**
45+
* Coupon duration
46+
* @var string once
47+
*/
2748
private $duration;
49+
50+
/**
51+
* Coupon name & coupon id
52+
* @var string must be camel_case
53+
*/
2854
private $name;
55+
56+
/**
57+
* Coupon duration month
58+
* @var integer
59+
*/
2960
private $durationMonth;
61+
62+
/**
63+
* All coupon data for create
64+
* @var [type]
65+
*/
3066
private $couponData;
3167

3268
public function __construct()

src/StripePlans.php

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
* @copyright Kawsar Soft. (http://kawsarsoft.com)
88
*/
99

10-
use Stripe\Customer;
10+
use Stripe\Product;
1111
use Stripe\Stripe;
1212
use Stripe\Plan;
13-
use Stripe\Product;
1413
use Config;
1514

16-
// https://stripe.com/docs/api/plans/create
17-
15+
/**
16+
* Plan class.
17+
* @source https://stripe.com/docs/api/plans/create
18+
*/
1819
class StripePlans
1920
{
2021
/**
@@ -26,16 +27,33 @@ class StripePlans
2627
* Customer all data after create
2728
* @var object
2829
*/
30+
31+
/**
32+
* Set currency for plan.
33+
* @var string
34+
*/
2935
private $currency;
3036

37+
/**
38+
* [private description]
39+
* @var [type]
40+
*/
3141
private $interval;
3242

43+
/**
44+
* Plan price.
45+
* @var integer|float
46+
*/
3347
private $amount;
3448

3549
private $product = [];
3650

3751
private $extra = [];
3852

53+
/**
54+
* Trail day
55+
* @var integer
56+
*/
3957
private $trial;
4058

4159
public function __construct()
@@ -87,12 +105,21 @@ public function extra ($data)
87105
return $this;
88106
}
89107

108+
/**
109+
* Plan trial time (day).
110+
* @param integer $day
111+
* @return $this
112+
*/
90113
public function trial($day)
91114
{
92115
$this->trial = $day;
93116
return $this;
94117
}
95118

119+
/**
120+
* Create plan & retrive data.
121+
* @return object
122+
*/
96123
public function get()
97124
{
98125
try {
@@ -111,6 +138,11 @@ public function get()
111138
}
112139
}
113140

141+
/**
142+
* Retrieve a plan with $id.
143+
* @param string $id
144+
* @return object
145+
*/
114146
public function retrieve($id)
115147
{
116148
try {
@@ -122,6 +154,11 @@ public function retrieve($id)
122154
}
123155
}
124156

157+
/**
158+
* Delete a plan and same time delete product.
159+
* @param string $id
160+
* @return object
161+
*/
125162
public function delete($id)
126163
{
127164
try {
@@ -139,6 +176,11 @@ public function delete($id)
139176
}
140177
}
141178

179+
/**
180+
* Active a plan
181+
* @param string $id
182+
* @return object
183+
*/
142184
public function active($id)
143185
{
144186
try {
@@ -154,6 +196,11 @@ public function active($id)
154196
}
155197
}
156198

199+
/**
200+
* Deactive a plan.
201+
* @param string $id
202+
* @return $this
203+
*/
157204
public function deactive($id)
158205
{
159206
try {

0 commit comments

Comments
 (0)