Commit 923a66491b2a1499bcd0675e73aebea6b00e7a3a
1 parent
6d646f04
test privat for extrem
Showing
1 changed file
with
99 additions
and
0 deletions
Show diff stats
| 1 | +<?php | |
| 2 | + /** | |
| 3 | + * Created by PhpStorm. | |
| 4 | + * User: stes | |
| 5 | + * Date: 17.01.18 | |
| 6 | + * Time: 11:45 | |
| 7 | + */ | |
| 8 | + | |
| 9 | + namespace frontend\controllers; | |
| 10 | + | |
| 11 | + use GuzzleHttp\Client; | |
| 12 | + use yii\helpers\Json; | |
| 13 | + use yii\helpers\Url; | |
| 14 | + use yii\web\Controller; | |
| 15 | + | |
| 16 | + class PrivatController extends Controller | |
| 17 | + { | |
| 18 | + public function actionIndex(){ | |
| 19 | + $st = ''; | |
| 20 | + $privat[ 'products' ][ 0 ][ 'name' ] = 'test product'; | |
| 21 | + $privat[ 'products' ][ 0 ][ 'count' ] = 1; | |
| 22 | + $privat[ 'products' ][ 0 ][ 'price' ] =100; | |
| 23 | + $st .= $privat[ 'products' ][ 0 ][ 'name' ] . $privat[ 'products' ][ 0 ][ 'count' ] . str_replace( | |
| 24 | + '.', | |
| 25 | + '', | |
| 26 | + $privat[ 'products' ][ 0 ][ 'price' ] . '.00' | |
| 27 | + ); | |
| 28 | + | |
| 29 | + | |
| 30 | + $url = 'https://payparts2.privatbank.ua/ipp/v2/payment/create'; | |
| 31 | + $password = '310a8890988e478eadb5dc1175ab9297'; | |
| 32 | + $privat[ 'storeId' ] = '9F93C471A19F4DC4B5A1'; | |
| 33 | + $privat[ 'amount' ] = 100; | |
| 34 | + $privat[ 'partsCount' ] = 10; | |
| 35 | + $privat[ 'merchantType' ] = 'PP'; | |
| 36 | + $privat[ 'orderId' ] = date('Ymd-His'); | |
| 37 | + $privat[ 'responseUrl' ] = Url::to('/ru/privat/callback', true); | |
| 38 | + $privat[ 'redirectUrl' ] = Url::to('/site/index', true); | |
| 39 | + | |
| 40 | + $privat[ 'signature' ] = base64_encode( | |
| 41 | + sha1( | |
| 42 | + $password . $privat[ 'storeId' ] . $privat[ 'orderId' ] . str_replace( | |
| 43 | + ".", | |
| 44 | + "", | |
| 45 | + $privat[ 'amount' ] . '.00' | |
| 46 | + ) . $privat[ 'partsCount' ] . $privat[ 'merchantType' ] . $privat[ 'responseUrl' ] . $privat[ 'redirectUrl' ] . $st . $password, | |
| 47 | + true | |
| 48 | + ) | |
| 49 | + ); | |
| 50 | + | |
| 51 | + $headers = [ | |
| 52 | + 'Accept' => 'application/json', | |
| 53 | + 'Accept-Encoding' => 'UTF-8', | |
| 54 | + 'Content-Type' => 'application/json;charset=utf-8', | |
| 55 | + ]; | |
| 56 | + $client = new Client(); | |
| 57 | + | |
| 58 | + $response = $client->post( | |
| 59 | + $url, | |
| 60 | + [ | |
| 61 | + 'headers' => $headers, | |
| 62 | + 'body' => Json::encode($privat), | |
| 63 | + ] | |
| 64 | + ); | |
| 65 | + | |
| 66 | + if ($response->getStatusCode() == 200) { | |
| 67 | + $str = (string) $response->getBody() | |
| 68 | + ->getContents(); | |
| 69 | + $data = Json::decode($str); | |
| 70 | + if ($data[ 'token' ]) { | |
| 71 | + header( | |
| 72 | + 'Location: https://payparts2.privatbank.ua/ipp/v2/payment?token=' . $data[ 'token' ] | |
| 73 | + ); // перенаправление на нужную страницу | |
| 74 | + exit(); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + | |
| 80 | + public function actionCallback() | |
| 81 | + { | |
| 82 | + | |
| 83 | + if ($_SERVER[ 'REQUEST_METHOD' ] === 'POST') { | |
| 84 | + $data = file_get_contents('php://input'); | |
| 85 | + $file = \Yii::getAlias('@storage/callback.log'); | |
| 86 | + $myFile = fopen($file, 'a') or die('Unable to open file!'); | |
| 87 | + fwrite($myFile, "\n" . $data); | |
| 88 | + fclose($myFile); | |
| 89 | + | |
| 90 | + print_r($data); | |
| 91 | + } else { | |
| 92 | + print_r(Url::to('/ru/order/callback', true)); | |
| 93 | + print_r(\Yii::$app->session->get('data')); | |
| 94 | + } | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + } | |
| 99 | + } | |
| 0 | 100 | \ No newline at end of file | ... | ... |