OMNIPAY: Платеж Отсутствие: аутентификация не удалась из -за неверной учетной записи аутентификации или отсутствующего зPhp

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 OMNIPAY: Платеж Отсутствие: аутентификация не удалась из -за неверной учетной записи аутентификации или отсутствующего з

Сообщение Anonymous »

Я использую Omnipay для платежей PayPal, я получаю эту ошибку: < /p>

Код: Выделить всё

Payment failed: Authentication failed due to invalid authentication credentials or a missing Authorization header.
Это мой код на продажу, проверил на нескольких аккаунтах и ​​оба выдают ошибку. Поэтому мне трудно поверить, что это ошибка учетных данных.

Код: Выделить всё

public function generatePaypalPaymentByTransaction(Transaction $transaction) {
try {
$gateway = Omnipay::create('PayPal_Rest');
$gateway->setClientId(config('paypal.client_id'));
$gateway->setSecret(config('paypal.secret'));
$gateway->setTestMode(config('paypal.test_mode'));

$urlHost = rtrim(config('paypal.url_host'), '/') . '/';

if($transaction->type != Transaction::DEPOSIT_TYPE) {
$username = User::find($transaction->recipient_user_id)->username;
$username = rawurlencode($username); // Codificar el username para la URL
}
$returnUrl = $urlHost . 'pay/execute-payment' . '?transaction_id=' . $transaction->id;

if($transaction->type == Transaction::ROULETTE) {
$cancel_url = $urlHost . 'roulette/' . $username . '/' . $transaction->roulette_id;
} else {
$cancel_url = $urlHost . 'feed';
}

if($transaction->type == 'deposit') {
// Incrementa el amount en un 10%
$transaction->amount = $transaction->amount * 1.10;
}

$response = $gateway->purchase([
'amount' => $transaction->amount,
'currency' => config('paypal.currency'),
'returnUrl' => $returnUrl,
'cancelUrl' => $cancel_url,
])->send();

if($response->isRedirect()) {
$response->redirect();
} else {
return $response->getMessage();
}
} catch (Throwable $e){
return $e->getMessage();
}
}
Подтвердить продажу:

Код: Выделить всё

public function completePurchase($PayerID, $paymentId, $amount)
{
try {
Log::info("Pre Complte Purchase");
$response = $this->gateway->completePurchase([
'payer_id' => $PayerID,
'transactionReference' => $paymentId,
'amount' => $amount,
'currency' => env('PAYPAL_CURRENCY'),
])->send();
Log::info("Post Complte Purchase");
if ($response->isSuccessful()) {
Log::info('Payment completed successfully: ' . json_encode($response->getData()));
} else {
Log::error('Payment failed: ' .  $response->getMessage());
}

return $response;
} catch (Throwable $e){
return $e->getMessage();
}
}
И это код, который находится в функции успеха в маршруте подтверждения

Код: Выделить всё

 public function success (Request $request)
{
$transaction = Transaction::find($request->transaction_id);

Log::info("Request All");
Log::info($request->all());
$response = $this->completePurchase($request->PayerID, $request->paymentId, $request->amount);

if ($response instanceof \Omnipay\Common\Message\ResponseInterface && $response->isSuccessful()) {
// El pago se completó con éxito
Log::info('Payment completed successfully.');

} else {
// El pago falló
Log::error('Payment failed or an error occurred.');
// Actualizar el estado de la transacción a 'declined'
$transaction->status = Transaction::DECLINED_STATUS;
$transaction->save();

if($transaction->type === Transaction::ROULETTE) {
// Redirigir al usuario a la página de error
return redirect()->route('roulette.show', ['username' => rawurlencode(User::find($transaction->recipient_user_id)->username), 'roulette_id' => $transaction->roulette_id])
->with('error', __('Payment failed, please try again.'));
} else if ($transaction->type === Transaction::TIP_TYPE) {
// Redirigir al usuario a la página de error
return redirect()->route('profile', ['username' => rawurlencode(User::find($transaction->recipient_user_id)->username)])
->with('error', __('Payment failed, please try again.'));
} else {
// Redirigir al usuario a la página de error
return redirect()->route('feed')->with('error', __('Payment failed, please try again.'));
}
}
Здесь:

Подробнее здесь: https://stackoverflow.com/questions/793 ... cation-cre
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Php»