PHP code example of matperez / yii2-platron
1. Go to this page and download the library: Download matperez/yii2-platron library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
matperez / yii2-platron example snippets
php composer.phar
$response = $platron->initPayment(new \matperez\yii2platron\requests\InitPaymentRequest([
'amount' => 1000,
'orderId' => 1234,
'description' => 'amazing goods',
'params' => [
'custom_param' => 5
],
]));
$paymentIsInitiated = $response->isSuccess();
$redirectUrl = $response->getRedirectUrl();
$response = $platron->revoke(new \matperez\yii2platron\requests\RevokeRequest([
'refundAmount' => 1000,
'paymentId' => 1234,
]));
$transactionIsRevoked = $response->isSuccess();
$response = $platron->getStatus(new \matperez\yii2platron\requests\StatusRequest([
'payment_id' => 1234,
]));
$responseIsSuccess = $response->isSuccess();
$transactionIsComplete = $response->hasStatus(\matperez\yii2platron\Api::TRANSACTION_STATUS_OK);
/**
* @return array
* @throws BadRequestHttpException
* @throws ServerErrorHttpException
*/
public function actionResult()
{
$request = new ResultRequest(\Yii::$app->request->post());
if (!$request->validate()) {
throw new BadRequestHttpException('Invalid result request: '.var_export($request->errors, true));
}
$transaction = \Yii::$app->db->beginTransaction();
$response = new ResultResponse([
'status' => ResultResponse::STATUS_OK
]);
try {
// do something to commit or reject the payment..
$transaction->commit();
} catch (\Exception $e) {
$transaction->rollBack();
$response->status = ResultResponse::STATUS_ERROR;
$response->errorDescription = $e->getMessage();
}
try {
$data = $this->platron->prepareParams($_SERVER['REQUEST_URI'], $response->getResponseAttributes());
} catch (\Exception $e) {
throw new ServerErrorHttpException('Unable to prepare the response: '.$e->getMessage(), $e->getCode(), $e);
}
\Yii::$app->response->format = Response::FORMAT_XML;
return $data;
}