} catch (\Exception $e) { echo $e->getMessage(); } return $instanceIdResponse->getInstanceId(); }); /** * app route */ $app->get('/request-external-payment', function (Request $request) use($app) { $apiFacade = YandexMoney::getApiFacade(); $apiFacade->setLogFile(__DIR__ . '/ym.log'); $externalPaymentResponse = null; $externalProcessPaymentResponse = null; try { $instanceIdResponse = $apiFacade->getInstanceId(CLIENT_ID); $externalPaymentP2pRequest = new ExternalP2pPaymentRequest(); $externalPaymentP2pRequest->setTo("410011161616877"); $externalPaymentP2pRequest->setAmount("20.50"); $externalPaymentP2pRequest->setMessage("Message"); $externalPaymentResponse = $apiFacade->requestExternalPaymentP2p($instanceIdResponse->getInstanceId(), $externalPaymentP2pRequest); $processExternalPaymentRequest = new ProcessExternalPaymentRequest(); $processExternalPaymentRequest->setRequestId($externalPaymentResponse->getRequestId()); $processExternalPaymentRequest->setInstanceId($instanceIdResponse->getInstanceId()); $processExternalPaymentRequest->setExtAuthSuccessUri("http://somewhere.com/success"); $processExternalPaymentRequest->setExtAuthFailUri("http://somewhere.com/fail"); $externalProcessPaymentResponse = $apiFacade->processExternalPayment($processExternalPaymentRequest); } catch (\Exception $e) { echo $e->getMessage(); } $response = array(); if ($externalProcessPaymentResponse != null) {
public function requestExternalPaymentP2p($instanceId, ExternalP2pPaymentRequest $externalP2pPaymentRequest) { $postParamsArray = array(); $postParamsArray[ApiKey::PATTERN_ID] = ApiValue::P2P; $postParamsArray[ApiKey::INSTANCE_ID] = $instanceId; $postParamsArray[ApiKey::TO] = $externalP2pPaymentRequest->getTo(); $postParamsArray[ApiKey::MESSAGE] = $externalP2pPaymentRequest->getMessage(); if ($externalP2pPaymentRequest->getAmount() > 0) { $postParamsArray[ApiKey::AMOUNT] = $externalP2pPaymentRequest->getAmount(); } else { if ($externalP2pPaymentRequest->getAmountDue() > 0) { $postParamsArray[ApiKey::AMOUNT_DUE] = $externalP2pPaymentRequest->getAmountDue(); } else { throw new \ErrorException("Sum for payment must be more than 0! Please check your params"); } } $apiNetworkClient = new ApiNetworkClient(); $apiResponse = $apiNetworkClient->request($this->getApiUri(Uri::REQUEST_EXTERNAL_PAYMENT), http_build_query($postParamsArray)); return new Responses\ExternalPaymentResponse($apiResponse->getBodyJsonDecoded()); }