Клиент для проведения платежей API Тинькофф Платежи.
composer require paveldanilin/php-tinkoff-payment
/** @var PaymentClientInterface $paymentClient */
$paymentClient = PaymentClient::create('<terminal_key>', '<password>');
$payment = newPayment()
->amount(1000)
->orderId('1234')
->oneStep()
->build();
/** @var NewPaymentResultInterface $result */
$result = $paymentClient->init($payment);
if ($result->isSuccess()) {
print 'PaymentId: ' . $result->getPaymentId() . "\n";
print 'PaymentURL: ' . $result->getPaymentURL() . "\n";
} else {
print 'Error: ' . $result->getMessage() . "\n";
}
$payment = newPayment()
->orderId('33101')
->oneStep()
->receipt(newReceipt()
->email('pavel.k.danilin@gmail.com')
->taxationOSN()
->addItem(newReceiptItem()
->name('Кружка')
->price(1000)
->quantity(1)
->taxNone()
->build())
->build())
->build();
/** @var NewPaymentResultInterface $result */
$result = $paymentClient->init($payment);
if ($result->isSuccess()) {
print 'PaymentId: ' . $result->getPaymentId() . "\n";
print 'PaymentURL: ' . $result->getPaymentURL() . "\n";
} else {
print 'Error: ' . $result->getMessage() . "\n";
}
/** @var CancelResultInterface $result */
$result = $paymentClient->cancel(1645861116);
if ($result->isSuccess()) {
print 'PaymentId: ' . $result->getPaymentId() . ' [' . $result->getStatus() . "]\n";
} else {
print 'Error: ' . $result->getMessage() . "\n";
}
API получение текущего статуса платежа
/** @var GetStateResultInterface $result */
$result = $paymentClient->getState(1645861116);
if ($result->isSuccess()) {
print 'PaymentId: ' . $result->getPaymentId() . ' [' . $result->getStatus() . "]\n";
} else {
print 'Error: ' . $result->getMessage() . "\n";
}
/** @var CheckOrderResultInterface $result */
$result = $paymentClient->checkOrder('333335556669');
if ($result->isSuccess()) {
print 'OrderID: ' . $result->getOrderId() . "\n";
print '-----' . "\n";
foreach ($result->getPayments() as $payment) {
print 'PaymentID: ' . $payment->getPaymentId() . "\n";
print 'Status: ' . $payment->getStatus() . "\n";
print 'Success: ' . $payment->getSuccess() . "\n";
print 'RRN: ' . $payment->getRRN() . "\n";
print '=====' . "\n";
}
} else {
print 'Error: ' . $result->getMessage() . "\n";
}
API повторной отправки неуспешных нотификаций
/** @var ResendResultInterface $result */
$result = $paymentClient->resendNotifications();
if ($result->isSuccess()) {
print 'Count: ' . $result->getCount() . "\n";
} else {
print 'Error: ' . $result->getMessage() . "\n";
}
Вызовите метод Init с параметрами Recurrent и CustomerKey Переадресуйте покупателя на страницу оплаты и дождитесь совершения платежа В нотификации AUTHORIZED или CONFIRMED получите и сохраните идентификатор RebillID
$charge = new Charge();
$charge->setPaymentId(10063);
$charge->setRebillId(1234);
$result = $paymentClient->charge($charge);
if ($result->isSuccess()) {
// Успех
} else {
// Ошибка
}
composer test