From 1f11d88d6b23bf5752c510e803ad4a6903e299a9 Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Tue, 24 May 2016 18:00:59 -0400 Subject: [PATCH] Store ip addresses for payments and payment methods --- app/Http/Controllers/ClientPortalController.php | 4 ++-- app/Http/Controllers/PaymentController.php | 2 +- app/Services/PaymentService.php | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index 578b960b1160..50058c8bc809 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -835,7 +835,7 @@ class ClientPortalController extends BaseController $gateway = $accountGateway->gateway; if ($token && $paymentType == PAYMENT_TYPE_BRAINTREE_PAYPAL) { - $sourceReference = $this->paymentService->createToken($this->paymentService->createGateway($accountGateway), array('token'=>$token), $accountGateway, $client, $invitation->contact_id); + $sourceReference = $this->paymentService->createToken($this->paymentService->createGateway($accountGateway), array('token'=>$token), $accountGateway, $client, $contact->id); if(empty($sourceReference)) { $this->paymentMethodError('Token-No-Ref', $this->paymentService->lastError, $accountGateway); @@ -916,7 +916,7 @@ class ClientPortalController extends BaseController if (!empty($details)) { $gateway = $this->paymentService->createGateway($accountGateway); - $sourceReference = $this->paymentService->createToken($gateway, $details, $accountGateway, $client, $invitation->contact_id); + $sourceReference = $this->paymentService->createToken($gateway, $details, $accountGateway, $client, $contact->id); } else { return Redirect::to('client/paymentmethods/add/' . $typeLink)->withInput(Request::except('cvv')); } diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 6a5742fabe2b..07d20a1571b9 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -667,7 +667,7 @@ class PaymentController extends BaseController } elseif (method_exists($gateway, 'completePurchase') && !$accountGateway->isGateway(GATEWAY_TWO_CHECKOUT) && !$accountGateway->isGateway(GATEWAY_CHECKOUT_COM)) { - $details = $this->paymentService->getPaymentDetails($invitation, $accountGateway); + $details = $this->paymentService->getPaymentDetails($invitation, $accountGateway, array()); $response = $this->paymentService->completePurchase($gateway, $accountGateway, $details, $token); diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index b227b466413c..c80e193b82de 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -88,6 +88,10 @@ class PaymentService extends BaseService 'transactionType' => 'Purchase', ]; + if ($input !== null) { + $data['ip_address'] = \Request::ip(); + } + if ($accountGateway->isGateway(GATEWAY_PAYPAL_EXPRESS) || $accountGateway->isGateway(GATEWAY_PAYPAL_PRO)) { $data['ButtonSource'] = 'InvoiceNinja_SP'; }; @@ -442,6 +446,8 @@ class PaymentService extends BaseService $accountGatewayToken->save(); $paymentMethod = $this->convertPaymentMethodFromGatewayResponse($tokenResponse, $accountGateway, $accountGatewayToken, $contactId); + $paymentMethod->ip_address = \Request::ip(); + $paymentMethod->save(); } else { $this->lastError = $tokenResponse->getMessage(); @@ -644,6 +650,10 @@ class PaymentService extends BaseService $payment->payment_type_id = $this->detectCardType($card->getNumber()); } + if (!empty($paymentDetails['ip_address'])) { + $payment->ip_address = $paymentDetails['ip_address']; + } + $savePaymentMethod = !empty($paymentMethod); // This will convert various gateway's formats to a known format