Last active
November 17, 2017 08:06
-
-
Save unalt/940a3cc94f907cd9b255c627f08dd312 to your computer and use it in GitHub Desktop.
Класс для работы с сбербанк эквайринг rest api php
From https://hello-site.ru/share/klass-dlya-raboty-s-sberbank-e/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
class CSberbank{ | |
private static $login = "login"; | |
private static $username = "user"; | |
private static $password = "password"; | |
function getOrderStatus( $orderId ) { | |
// https:/server/application_context/rest/getOrderStatus.do? orderId=b8d70aa7-bfb3-4f94-b7bb-aec7273e1fce&language=ru&password=password&userName=userName | |
$url = "https://3dsec.sberbank.ru/payment/rest/getOrderStatus.do?orderId=".$orderId."&language=ru&password=".$this::$password."&userName=".$this::$username; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
if( $response ){ | |
$response = json_decode($response, true); | |
if( $response['ErrorMessage'] ){ | |
if( $response['OrderStatus'] == 2 ){ | |
return "Спасибо, заказ №".$response['OrderNumber']." оплачен."; | |
} else { | |
return "Статус заказа: ".$response['ErrorMessage']; | |
} | |
} | |
} | |
return false; | |
} | |
function registerOrder($total, $order, $returnUrl){ | |
$url = "https://3dsec.sberbank.ru/payment/rest/register.do?amount=".intval($total)."00¤cy=643&language=ru&orderNumber=".$order."&password=".$this::$password."&userName=".$this::$username."&returnUrl=".$returnUrl."&returnUrl=".$returnUrl."&pageView=DESKTOP&sessionTimeoutSecs=1200"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
if( $response ){ | |
$response = json_decode($response, true); | |
if( $response['orderId'] && $response['formUrl'] ){ | |
return 'redirect:'.$response['formUrl']; | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment