@@ -34,6 +34,7 @@ public function payment($payment_form_data, $order_data, $auto_submit = false)
3434 $ secret_key
3535 )));
3636
37+
3738 $ view = wa ()->getView ();
3839 $ view ->assign ('domain ' , $ domain );
3940 $ view ->assign ('public_key ' , $ public_key );
@@ -42,7 +43,34 @@ public function payment($payment_form_data, $order_data, $auto_submit = false)
4243 $ view ->assign ('desc ' , urlencode ($ desc ));
4344 $ view ->assign ('signature ' , $ signature );
4445
45- return $ view ->fetch ($ this ->path . '/templates/payment.html ' );
46+ $ has_phone = $ order ->contact_phone && (strlen ($ order ->contact_phone ) > 0 );
47+ $ has_email = $ order ->contact_email && (strlen ($ order ->contact_email ) > 0 );
48+
49+ if ($ has_phone ) {
50+ $ contact_phone = preg_replace ('/\D/ ' , '' , $ order ->contact_phone );
51+ $ view ->assign ('customerPhone ' , $ contact_phone );
52+ }
53+
54+ if ($ has_email ) {
55+ $ view ->assign ('customerEmail ' , $ order ->contact_email );
56+ }
57+
58+ if ($ has_phone || $ has_email ) {
59+ $ cashItems = $ this ->getCashItems ($ order );
60+ $ view ->assign ('cashItems ' , $ cashItems );
61+ }
62+
63+ if ($ has_phone && !$ has_email ) {
64+ $ template = $ this ->path . '/templates/payment_with_phone.html ' ;
65+ } elseif (!$ has_phone && $ has_email ) {
66+ $ template = $ this ->path . '/templates/payment_with_email.html ' ;
67+ } elseif ($ has_phone && $ has_email ) {
68+ $ template = $ this ->path . '/templates/payment_with_both.html ' ;
69+ } else {
70+ $ template = $ this ->path . '/templates/payment.html ' ;
71+ }
72+
73+ return $ view ->fetch ($ template );
4674 }
4775
4876 protected function callbackInit ($ request )
@@ -144,4 +172,45 @@ protected function returnJson($message)
144172 'message ' => json_encode ($ message )
145173 );
146174 }
147- }
175+
176+ private function getCashItems ($ order )
177+ {
178+ $ currencyCode = $ order ['currency ' ];
179+
180+ $ orderProducts = array_map (function ($ item ) use ($ currencyCode , $ order ) {
181+ $ vat = 'none ' ;
182+
183+ if (isset ($ order ['tax_included ' ]) && $ order ['tax_included ' ]) {
184+ $ vat = 'vat20 ' ;
185+ }
186+
187+ return array (
188+ 'name ' => $ item ['name ' ],
189+ 'count ' => $ item ['quantity ' ],
190+ 'price ' => round ($ item ['price ' ], 2 ),
191+ 'currency ' => $ currencyCode ,
192+ 'type ' => 'commodity ' ,
193+ 'nds ' => $ vat ,
194+ );
195+ }, $ order ['items ' ]);
196+
197+ if (isset ($ order ['shipping ' ]) && ($ order ['shipping ' ] > 0 ) && isset ($ order ['shipping_name ' ])) {
198+ $ vat = 'none ' ;
199+
200+ if (isset ($ order ['tax_included ' ]) && $ order ['tax_included ' ]) {
201+ $ vat = 'vat20 ' ;
202+ }
203+
204+ $ orderProducts [] = array (
205+ 'name ' => $ order ['shipping_name ' ],
206+ 'count ' => 1 ,
207+ 'price ' => round ($ order ['shipping ' ], 2 ),
208+ 'currency ' => $ currencyCode ,
209+ 'type ' => 'service ' ,
210+ 'nds ' => $ vat ,
211+ );
212+ }
213+
214+ return base64_encode (json_encode ($ orderProducts ));
215+ }
216+ }
0 commit comments