private function process(ExternalPayment $external_payment) { $process_options = array('request_id' => $this->request_id, 'instance_id' => $this->instance_id, 'ext_auth_success_uri' => $this->router->generate('subscribe_callback_success', [], Router::ABSOLUTE_URL), 'ext_auth_fail_uri' => $this->router->generate('subscribe_callback_fail', [], Router::ABSOLUTE_URL)); $count = 0; do { $result = $external_payment->process($process_options); if ('in_progress' === $result->status) { sleep(1); $count++; } } while ('in_progress' === $result->status && $count < 10); if ('ext_auth_required' !== $result->status) { throw new \Exception(); } return $result; }
$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"); if (is_null($request_id) || is_null($instance_id)) { $params = array("text" => "cookie is expired or incorrect", "home" => "../"); return show_error($params, $app); } $api = new ExternalPayment($instance_id); $base_path = "http://" . $app->request->getHostWithPort() . $app->request->getPath() . ".."; do { $result = $api->process(array("request_id" => $request_id, "ext_auth_success_uri" => $base_path . "/external-success/", "ext_auth_fail_uri" => $base_path . "/../external-fail/")); if ($result->status == "in_progress") { sleep(1); } } while ($result->status == "in_progress"); $get_cookie_json = function ($cookie_name) use($app) { return json_decode($app->getCookie($cookie_name)); }; $codesamples_base = "external_payment/wallet/"; 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->get("/wallet/external-fail/", function () use($app) { $params = array("text" => "Check out GET params for additional information", "home" => "../../");
function testGetInstanceId() { $response = \YandexMoney\ExternalPayment::getInstanceId(CLIENT_ID); $this->assertEquals($response->status, "success"); }