4
4
5
5
Described in [ Get it started] ( get-it-started.md )
6
6
7
+ ## Payment model
8
+
9
+ * Configuration
10
+
11
+ ``` bash
12
+ $ php composer.phar require payum/payum-laravel-package payum/offline
13
+ ```
14
+
15
+ ``` php
16
+ // bootstrap/start.php
17
+
18
+ App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
19
+ $payumBuilder
20
+ ->addGateway('offline', ['factory' => 'offline'])
21
+ ;
22
+ });
23
+ ```
24
+
25
+ * Prepare payment
26
+
27
+ ``` php
28
+ <?php
29
+ // app/controllers/PaymentController.php
30
+
31
+ use Payum\LaravelPackage\Controller\PayumController;
32
+
33
+ cclass PaymentController extends PayumController
34
+ {
35
+ public function preparePayment()
36
+ {
37
+ $storage = $this->getPayum()->getStorage('Payum\Core\Model\Payment');
38
+
39
+ $payment = $storage->create();
40
+ $payment->setNumber(uniqid());
41
+ $payment->setCurrencyCode('EUR');
42
+ $payment->setTotalAmount(123); // 1.23 EUR
43
+ $payment->setDescription('A description');
44
+ $payment->setClientId('anId');
45
+ $payment->setClientEmail('
[email protected] ');
46
+ $payment->setDetails(array(
47
+ // put here any fields in a gateway format.
48
+ // for example if you use Paypal ExpressCheckout you can define a description of the first item:
49
+ // 'L_PAYMENTREQUEST_0_DESC0' => 'A desc',
50
+ ));
51
+ $storage->update($payment);
52
+
53
+ $captureToken = $payum->getTokenFactory()->createCaptureToken('offline', $payment, 'payment_done');
54
+
55
+ return \Redirect::to($captureToken->getTargetUrl());
56
+ }
57
+ }
58
+ ```
59
+
7
60
## Stripe.Js
8
61
9
62
* Configuration
10
63
11
64
``` bash
12
65
$ php composer.phar require payum/payum-laravel-package stripe/stripe-php payum/stripe
13
- $ php artisan config:publish payum/payum-laravel-package
14
66
```
15
67
16
68
``` php
17
- // app/config/packages/payum/payum-laravel-package/config.php
18
-
19
- use Payum\LaravelPackage\Action\GetHttpRequestAction;
20
- use Payum\Core\Storage\FilesystemStorage;
21
-
22
- $detailsClass = 'Payum\Core\Model\ArrayObject';
23
- $tokenClass = 'Payum\Core\Model\Token';
24
-
25
- $stripeJsGatewayFactory = new \Payum\Stripe\StripeJsGatewayFactory();
26
-
27
- return array(
28
- 'token_storage' => new FilesystemStorage(__DIR__.'/../../../../storage/payments', $tokenClass, 'hash'),
29
- 'gateways' => array(
30
- 'stripe_js' => $stripeJsGatewayFactory->create(array(
31
- 'publishable_key' => $_SERVER['payum.stripe.publishable_key'],
32
- 'secret_key' => $_SERVER['payum.stripe.secret_key'],
33
- 'payum.action.get_http_request' => new GetHttpRequestAction(),
34
- )),
35
- ),
36
- 'storages' => array(
37
- $detailsClass => new FilesystemStorage(__DIR__.'/../../../../storage/payments', $detailsClass),
38
- )
39
- );
69
+ // bootstrap/start.php
70
+
71
+ App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
72
+ $payumBuilder
73
+ ->addGateway('stripe_js', [
74
+ 'factory' => 'stripe_js',
75
+ 'publishable_key' => 'EDIT ME',
76
+ 'secret_key' => 'EDIT ME',
77
+ ])
78
+ ;
79
+ });
40
80
```
41
81
42
82
* Prepare payment
43
83
44
84
``` php
45
85
<?php
46
- // app/controllers/PaypalController .php
86
+ // app/controllers/StripeController .php
47
87
48
- cclass StripeController extends BaseController
88
+ use Payum\LaravelPackage\Controller\PayumController;
89
+
90
+ cclass StripeController extends PayumController
49
91
{
50
92
public function prepareJs()
51
93
{
52
- $storage = \App::make('payum' )->getStorage('Payum\Core\Model\ArrayObject');
94
+ $storage = $this->getPayum( )->getStorage('Payum\Core\Model\ArrayObject');
53
95
54
96
$details = $storage->create();
55
97
$details['amount'] = '100';
56
98
$details['currency'] = 'USD';
57
99
$details['description'] = 'a desc';
58
100
$storage->update($details);
59
101
60
- $captureToken = \App::make('payum.security.token_factory' )->createCaptureToken('stripe_js', $details, 'payment_done');
102
+ $captureToken = $this->getPayum()->getTokenFactory( )->createCaptureToken('stripe_js', $details, 'payment_done');
61
103
62
104
return \Redirect::to($captureToken->getTargetUrl());
63
105
}
@@ -70,54 +112,43 @@ cclass StripeController extends BaseController
70
112
71
113
``` bash
72
114
$ php composer.phar require payum/stripe payum/payum-laravel-package stripe/stripe-php
73
- $ php artisan config:publish payum/payum-laravel-package
74
115
```
75
116
76
117
``` php
77
- // app/config/packages/payum/payum-laravel-package/config.php
78
-
79
- use Payum\LaravelPackage\Action\GetHttpRequestAction;
80
- use Payum\Core\Storage\FilesystemStorage;
81
-
82
- $detailsClass = 'Payum\Core\Model\ArrayObject';
83
- $tokenClass = 'Payum\Core\Model\Token';
118
+ // bootstrap/start.php
84
119
85
- $stripeCheckoutGatewayFactory = new \Payum\Stripe\StripeCheckoutGatewayFactory();
86
-
87
- return array(
88
- 'token_storage' => new FilesystemStorage(__DIR__.'/../../../../storage/payments', $tokenClass, 'hash'),
89
- 'gateways' => array(
90
- 'stripe_checkout' => $stripeCheckoutGatewayFactory->create(array(
120
+ App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
121
+ $payumBuilder
122
+ ->addGateway('stripe_checkout', [
123
+ 'factory' => 'stripe_checkout',
91
124
'publishable_key' => 'EDIT ME',
92
125
'secret_key' => 'EDIT ME',
93
- 'payum.action.get_http_request' => new GetHttpRequestAction(),
94
- )),
95
- ),
96
- 'storages' => array(
97
- $detailsClass => new FilesystemStorage(__DIR__.'/../../../../storage/payments', $detailsClass),
98
- )
99
- );
126
+ ])
127
+ ;
128
+ });
100
129
```
101
130
102
131
* Prepare payment
103
132
104
133
``` php
105
134
<?php
106
- // app/controllers/PaypalController.php
135
+ // app/controllers/StripeController.php
136
+
137
+ use Payum\LaravelPackage\Controller\PayumController;
107
138
108
- cclass StripeController extends BaseController
139
+ cclass StripeController extends PayumController
109
140
{
110
141
public function prepareCheckout()
111
142
{
112
- $storage = \App::make('payum' )->getStorage('Payum\Core\Model\ArrayObject');
143
+ $storage = $this->getPayum( )->getStorage('Payum\Core\Model\ArrayObject');
113
144
114
145
$details = $storage->create();
115
146
$details['amount'] = '100';
116
147
$details['currency'] = 'USD';
117
148
$details['description'] = 'a desc';
118
149
$storage->update($details);
119
150
120
- $captureToken = \App::make('payum.security.token_factory' )->createCaptureToken('stripe_checkout', $details, 'payment_done');
151
+ $captureToken = $this->getPayum()->getTokenFactory( )->createCaptureToken('stripe_checkout', $details, 'payment_done');
121
152
122
153
return \Redirect::to($captureToken->getTargetUrl());
123
154
}
@@ -130,56 +161,45 @@ cclass StripeController extends BaseController
130
161
131
162
``` bash
132
163
$ php composer.phar require payum/omnipay-bridge payum/payum-laravel-package omnipay/stripe
133
- $ php artisan config:publish payum/payum-laravel-package
134
164
```
135
165
136
166
``` php
137
- // app/config/packages/payum/payum-laravel-package/config .php
167
+ // bootstrap/start .php
138
168
139
- use Payum\LaravelPackage\Action\GetHttpRequestAction;
140
- use Payum\Core\Storage\FilesystemStorage;
141
-
142
- $detailsClass = 'Payum\Core\Model\ArrayObject';
143
- $tokenClass = 'Payum\Core\Model\Token';
144
-
145
- $omnipayDirectGatewayFactory = new \Payum\OmnipayBridge\OmnipayDirectGatewayFactory();
146
-
147
- return array(
148
- 'token_storage' => new FilesystemStorage(__DIR__.'/../../../../storage/payments', $tokenClass, 'hash'),
149
- 'gateways' => array(
150
- 'stripe_direct' => $omnipayDirectGatewayFactory->create(array(
169
+ App::resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
170
+ $payumBuilder
171
+ ->addGateway('stripe_direct', [
172
+ 'factory' => 'omnipay_direct',
151
173
'type' => 'Stripe',
152
174
'options' => array(
153
175
'apiKey' => 'EDIT ME',
154
176
'testMode' => true,
155
177
),
156
- 'payum.action.obtain_credit_card' => new ObtainCreditCardAction,
157
- )),
158
- ),
159
- 'storages' => array(
160
- $detailsClass => new FilesystemStorage(__DIR__.'/../../../../storage/payments', $detailsClass),
161
- )
162
- );
178
+ ])
179
+ ;
180
+ });
163
181
```
164
182
165
183
* Prepare payment
166
184
167
185
``` php
168
186
<?php
169
- // app/controllers/PaypalController.php
187
+ // app/controllers/OmnipayController.php
188
+
189
+ use Payum\LaravelPackage\Controller\PayumController;
170
190
171
- cclass StripeController extends BaseController
191
+ cclass OmnipayController extends PayumController
172
192
{
173
193
public function prepareDirect()
174
194
{
175
- $storage = \App::make('payum' )->getStorage('Payum\Core\Model\ArrayObject');
195
+ $storage = $this->getPayum( )->getStorage('Payum\Core\Model\ArrayObject');
176
196
177
197
$details = $storage->create();
178
198
$details['amount'] = '10.00';
179
199
$details['currency'] = 'USD';
180
200
$storage->update($details);
181
201
182
- $captureToken = \App::make('payum.security.token_factory' )->createCaptureToken('stripe_direct', $details, 'payment_done');
202
+ $captureToken = $this->getPayum()->getTokenFactory( )->createCaptureToken('stripe_direct', $details, 'payment_done');
183
203
184
204
return \Redirect::to($captureToken->getTargetUrl());
185
205
}
0 commit comments