@@ -12,31 +12,28 @@ public function redirectAction()
12
12
$ service = $ this ->container ->get ('quickpay_payment.quickpay_service ' );
13
13
14
14
try {
15
- $ user = $ this ->getUser ();
16
- $ billing = $ user ['billingaddress ' ];
17
-
18
- $ paymentId = $ this ->createPaymentUniqueId ();
19
- $ token = $ service ->createPaymentToken ($ this ->getAmount (), $ billing ['customernumber ' ]);
20
-
21
- //Save order and grab ordernumber
22
- $ orderNumber = $ this ->saveOrder ($ paymentId , $ token , \Shopware \Models \Order \Status::PAYMENT_STATE_OPEN );
23
-
24
- //Save orderNumber to session
25
- Shopware ()->Session ()->offsetSet ('quickpay_order_id ' , $ orderNumber );
26
- Shopware ()->Session ()->offsetSet ('quickpay_order_token ' , $ token );
27
-
28
15
$ paymentParameters = [
29
- 'order_id ' => $ orderNumber ,
30
16
'currency ' => $ this ->getCurrencyShortName (),
31
- 'variables ' => [
32
- 'payment_id ' => $ paymentId ,
33
- 'token ' => $ token
34
- ],
35
17
];
36
-
37
- //Create payment
38
- $ payment = $ service ->createPayment ($ paymentParameters );
39
-
18
+
19
+ //Save order and grab ordernumber
20
+ $ paymentId = Shopware ()->Session ()->offsetGet ('quickpay_payment_id ' );
21
+ if (empty ($ paymentId ))
22
+ {
23
+ //Create new QuickPay payment
24
+ $ orderId = $ service ->createOrderId ();
25
+
26
+ $ payment = $ service ->createPayment ($ orderId , $ paymentParameters );
27
+ }
28
+ else
29
+ {
30
+ //Update existing QuickPay payment
31
+ $ payment = $ service ->updatePayment ($ paymentId , $ paymentParameters );
32
+ }
33
+
34
+ // Save ID to session
35
+ Shopware ()->Session ()->offsetSet ('quickpay_payment_id ' , $ payment ->id );
36
+
40
37
$ user = $ this ->getUser ();
41
38
$ email = $ user ['additional ' ]['user ' ]['email ' ];
42
39
@@ -49,14 +46,7 @@ public function redirectAction()
49
46
$ this ->getCancelUrl (),
50
47
$ this ->getCallbackUrl ()
51
48
);
52
-
53
- $ repository = Shopware ()->Models ()->getRepository (\Shopware \Models \Order \Order::class);
54
- $ order = $ repository ->findOneBy (array (
55
- 'number ' => $ orderNumber
56
- ));
57
- $ order ->getAttribute ()->setQuickpayPaymentLink ($ paymentLink );
58
- Shopware ()->Models ()->flush ($ order ->getAttribute ());
59
-
49
+
60
50
$ this ->redirect ($ paymentLink );
61
51
} catch (\Exception $ e ) {
62
52
die ($ e ->getMessage ());
@@ -90,17 +80,17 @@ public function callbackAction()
90
80
if (!$ testmode && ($ response ->test_mode === true )) {
91
81
92
82
//Set order as cancelled
93
- $ this ->savePaymentStatus ($ response ->variables -> payment_id , $ response ->variables -> token , \Shopware \Models \Order \Status::PAYMENT_STATE_THE_PROCESS_HAS_BEEN_CANCELLED );
83
+ $ this ->savePaymentStatus ($ response ->order_id , $ response ->id , \Shopware \Models \Order \Status::PAYMENT_STATE_THE_PROCESS_HAS_BEEN_CANCELLED );
94
84
Shopware ()->PluginLogger ()->info ("Order attempted paid with testcard while testmode was disabled " );
95
85
return ;
96
86
}
97
87
98
88
//Set order as reserved
99
- $ this ->savePaymentStatus ($ response ->variables -> payment_id , $ response ->variables -> token , \Shopware \Models \Order \Status::PAYMENT_STATE_RESERVED );
89
+ $ this ->savePaymentStatus ($ response ->order_id , $ response ->id , \Shopware \Models \Order \Status::PAYMENT_STATE_RESERVED );
100
90
}
101
91
} else {
102
92
//Cancel order
103
- $ this ->savePaymentStatus ($ response ->variables -> payment_id , $ response ->variables -> token , \Shopware \Models \Order \Status::PAYMENT_STATE_THE_PROCESS_HAS_BEEN_CANCELLED );
93
+ $ this ->savePaymentStatus ($ response ->order_id , $ response ->id , \Shopware \Models \Order \Status::PAYMENT_STATE_THE_PROCESS_HAS_BEEN_CANCELLED );
104
94
Shopware ()->PluginLogger ()->info ('Checksum mismatch ' );
105
95
}
106
96
}
@@ -111,6 +101,36 @@ public function callbackAction()
111
101
*/
112
102
public function successAction ()
113
103
{
104
+ /** @var \QuickPayPayment\Components\QuickPayService $service */
105
+ $ service = $ this ->container ->get ('quickpay_payment.quickpay_service ' );
106
+
107
+ $ paymentId = Shopware ()->Session ()->offsetGet ('quickpay_payment_id ' );
108
+
109
+ if (empty ($ paymentId ))
110
+ {
111
+ $ this ->redirect (['controller ' => 'checkout ' , 'action ' => 'confirm ' ]);
112
+ return ;
113
+ }
114
+
115
+ $ payment = $ service ->getPayment ($ paymentId );
116
+ if (empty ($ payment ) || !isset ($ payment ->order_id ))
117
+ {
118
+ $ this ->redirect (['controller ' => 'checkout ' , 'action ' => 'confirm ' ]);
119
+ return ;
120
+ }
121
+
122
+ $ orderNumber = $ this ->saveOrder ($ payment ->order_id , $ payment ->id , \Shopware \Models \Order \Status::PAYMENT_STATE_OPEN );
123
+
124
+ $ repository = Shopware ()->Models ()->getRepository (\Shopware \Models \Order \Order::class);
125
+ $ order = $ repository ->findOneBy (array (
126
+ 'number ' => $ orderNumber
127
+ ));
128
+ $ order ->getAttribute ()->setQuickpayPaymentLink ($ payment ->link ->url );
129
+ Shopware ()->Models ()->flush ($ order ->getAttribute ());
130
+
131
+ //Remove ID from session
132
+ Shopware ()->Session ()->offsetUnset ('quickpay_payment_id ' );
133
+
114
134
//Redirect to finish
115
135
$ this ->redirect (['controller ' => 'checkout ' , 'action ' => 'finish ' ]);
116
136
@@ -122,7 +142,7 @@ public function successAction()
122
142
*/
123
143
public function cancelAction ()
124
144
{
125
- $ this ->redirect (['controller ' => 'checkout ' , 'action ' => 'cancel ' ]);
145
+ $ this ->redirect (['controller ' => 'checkout ' , 'action ' => 'confirm ' ]);
126
146
}
127
147
128
148
/**
0 commit comments