Answer the question
In order to leave comments, you need to log in
How to print an object in JSON?
An object
class Required3DS
{
/**
* @var integer
*/
protected $transactionId;
/**
* @var string
*/
protected $token;
/**
* @var string
*/
protected $url;
/**
* @return integer
*/
/**
* @param $params
* @return Required3DS
*/
public static function fromArray($params)
{
$model = new Required3DS();
$model->setTransactionId($params['TransactionId']);
$model->setToken($params['PaReq']);
$model->setUrl($params['AcsUrl']);
return $model;
}
}
public function chargeCard($amount, $currency, $ipAddress, $cardHolderName, $cryptogram, $params = [], $requireConfirmation = false)
{
$endpoint = $requireConfirmation ? '/payments/cards/auth' : '/payments/cards/charge';
$defaultParams = [
'Amount' => $amount,
'Currency' => $currency,
'IpAddress' => $ipAddress,
'Name' => $cardHolderName,
'CardCryptogramPacket' => $cryptogram
];
$response = $this->sendRequest($endpoint, array_merge($defaultParams, $params));
if ($response['Success']) {
return Transaction::fromArray($response['Model']);
}
if ($response['Message']) {
throw new RequestException($response);
}
if (isset($response['Model']['ReasonCode']) && $response['Model']['ReasonCode'] !== 0) {
throw new PaymentException($response);
}
return Required3DS::fromArray($response['Model']);
}
if (Yii::$app->request->post('CardCryptogramPacket')){
$transaction = $client->chargeCard(230, 'RUB', Yii::$app->request->userIP, Yii::$app->request->post('Name'), Yii::$app->request->post('CardCryptogramPacket'), ['Email'=>'[email protected]', 'phone'=>'89178950879'], false);
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
//$transaction = ArrayHelper::toArray($transaction);
//$transaction = Json::decode($transaction);
return $transaction;
}
object(app\modules\main\module\CloudPayments\Model\Required3DS)#107 (3) { ["transactionId":protected]=> int(143396325) ["token":protected]=> string(234) "+/eyJNZXJjaGFudE5hbWUiOm51bGwsIkZpcnN0U2l4IjoiNDI0MjQyIiwiTGFzdEZvdXIiOiI0MjQyIiwiQW1vdW50IjoyMzAuMCwiQ3VycmVuY3lDb2RlIjoiUlVCIiwiRGF0ZSI6IjIwMTktMDUtMDlUMDA6MDA6MDArMDM6MDAiLCJDdXN0b21lck5hbWUiOm51bGwsIkN1bHR1cmVOYW1lIjoicnUtUlUifQ==" ["url":protected]=> string(33) "https://demo.cloudpayments.ru/acs" }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question