request() public method

Requests an external payment.
See also: http://api.yandex.com/money/doc/dg/reference/request-external-payment.xml
See also: https://tech.yandex.ru/money/doc/dg/reference/request-external-payment-docpage/
public request ( array[] $payment_options ) : response
$payment_options array[] Key-value parameters collection
return response object
Esempio n. 1
0
 private function getRequestId(ExternalPayment $external_payment)
 {
     $payment_options = array('pattern_id' => 'p2p', 'to' => $this->params['wallet'], 'amount' => $this->params['price'], 'message' => 'Подписка на газету FLStory');
     $response = $external_payment->request($payment_options);
     if ($response->status === 'success') {
         $this->request_id = $response->request_id;
     } else {
         throw new \Exception($response->message);
     }
 }
    $get_cookie_json = function ($cookie_name) use($app) {
        return json_decode($app->getCookie($cookie_name));
    };
    $codesamples_base = "external_payment/";
    return $app->render("cards.html", array("payment_result" => $result, "panels" => array("instance_id" => template_meta(array("code" => read_sample($codesamples_base . "obtain_instance_id.txt"), "response" => $get_cookie_json("result/instance_id")), 1), "request_payment" => template_meta(array("code" => read_sample($codesamples_base . "request_payment.txt"), "response" => $get_cookie_json("result/request")), 2), "process_payment1" => template_meta(array("code" => read_sample($codesamples_base . "process_payment1.txt"), "response" => $get_cookie_json("result/process")), 3), "process_payment2" => template_meta(array("code" => read_sample($codesamples_base . "process_payment2.txt"), "response" => $result), 4)), "home" => "../", "lang" => "PHP"));
});
$app->post("/wallet/process-external/", function () use($app) {
    $cookie_expired = "20 minutes";
    $wallet = $app->request->post("wallet");
    $value = $app->request->post("value");
    $instance_id_json = ExternalPayment::getInstanceId(CLIENT_ID);
    $app->setCookie("instance_id", $instance_id_json->instance_id, $cookie_expired, "/");
    $app->setCookie("result/instance_id", json_encode($instance_id_json), $cookie_expired, "/");
    $instance_id = $instance_id_json->instance_id;
    $api = new ExternalPayment($instance_id);
    $request_result = $api->request(array("pattern_id" => "p2p", "to" => $wallet, "amount_due" => $value, "comment" => "sample test payment", "message" => "sample test payment"));
    if ($request_result->status != "success") {
        $params = array("text" => json_encode($request_result, JSON_OPTIONS), "home" => "../");
        return show_error($params, $app);
    }
    $app->setCookie("request_id", $request_result->request_id, $cookie_expired, "/");
    $base_path = "http://" . $app->request->getHostWithPort() . $app->request->getPath() . "..";
    $process_result = $api->process(array("request_id" => $request_result->request_id, "ext_auth_success_uri" => $base_path . "/external-success/", "ext_auth_fail_uri" => $base_path . "/../external-fail/"));
    $app->setCookie("result/request", json_encode($request_result), $cookie_expired, "/");
    $app->setCookie("result/process", json_encode($process_result), $cookie_expired, "/");
    $url = sprintf("%s?%s", $process_result->acs_uri, http_build_query($process_result->acs_params));
    $app->redirect($url);
});
$app->get("/wallet/external-success/", function () use($app) {
    $request_id = $app->getCookie("request_id");
    $instance_id = $app->getCookie("instance_id");