public function accept($withdrawId) { $withdrawal = Withdrawal::findOrFail($withdrawId); $paypal = new PaypalPaymentService(); try { $amount = $withdrawal->amount; $result = $paypal->payout($withdrawal->user, $amount, $withdrawal->currency, $withdrawal->account, $withdrawal->id); } catch (\PayPal\Exception\PayPalConnectionException $e) { LogMapper::log('withdraw_error', $withdrawal->id, 'paypal', ['error' => json_decode($e->getData())]); return redirect('/admin/withdraw')->withErrors(['Paypal withdrawal failed', $e->getData()]); } if ($result->batch_header->batch_status == 'SUCCESS') { $withdrawal->admin_id = $this->user->id; $withdrawal->status = 'done'; $withdrawal->transaction_number = $result->batch_header->payout_batch_id; $withdrawal->response = $result->toArray(); $user = $withdrawal->user; $user->balance_blocked = $user->balance_blocked - $withdrawal->amount; $user->balance = $user->balance - $withdrawal->amount; if ($user->balance_blocked < 0) { $user->balance_blocked = 0; } if ($user->balance < 0) { $user->balance = 0; } $withdrawal->save(); $user->save(); NotificationMapper::withdrawAccept($withdrawal); LogMapper::log('withdraw_success', $withdrawal->id, 'paypal_success', ['amount' => $withdrawal->amount . $withdrawal->currency, 'withdrawal' => $amount . $withdrawal->currency, 'response' => $result->toArray()]); return redirect('/admin/withdraw/' . $withdrawal->id . '/show')->with(['success' => 'Withdraw accepted']); } else { LogMapper::log('withdraw_error', $withdrawal->id, 'paypal_failed', $result->toArray()); return redirect('/admin/withdraw')->withErrors(['Paypal withdrawal failed', json_encode($result->toArray())]); } }
public function success($taskId) { $paypalService = new PaypalPaymentService(); $paymentId = Input::get('paymentId'); $payerID = Input::get('PayerID'); $token = Input::get('token'); $task = new \stdClass(); $task->id = $taskId; $task->title = 'Task example title'; $task->total = 50.25; try { $paypalService->checkPaymentSession($paymentId, $task); } catch (\Exception $e) { Log::error('PayPal Error ' . $e->getMessage()); abort(404); return false; } // set task paid here dd($paymentId, $payerID, $token); }
public function paypalSuccess($userId) { $paypalService = new PaypalPaymentService(); $paymentId = Input::get('paymentId'); $payerID = Input::get('PayerID'); $token = Input::get('token'); try { $paypalService->checkPaymentSession($paymentId, $this->user); $paymentInfo = $paypalService->paymentInfo; $amount = $paymentInfo['amount']; LogMapper::log('paypal_success', $amount, $userId, $paymentInfo); } catch (\Exception $e) { LogMapper::log('paypal_error', $e->getMessage(), 'success_callback', ['user' => $this->user->id, 'paymentId' => $paymentId]); return Redirect::to('/user/client/billing')->withErrors(['paypal' => 'Failed paypal']); } $payment = PaymentMapper::refillFromPaypal($this->user, $paypalService); LogMapper::log('payment', $amount, 'refilled', ['payment_id' => $payment->id, 'merchant' => 'paypal']); NotificationMapper::refilled($payment); return Redirect::to('/user/client/billing')->with(['success' => 'We got your payment']); }