From 64dfe1d6c3d61c842748bfeae45868d811cacb52 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 25 Jan 2021 22:48:12 +1100 Subject: [PATCH 1/2] Minor fix for authorize.net --- .../Authorize/AuthorizeCreateCustomer.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreateCustomer.php b/app/PaymentDrivers/Authorize/AuthorizeCreateCustomer.php index 883fbcfd33c6..1adfb93b9273 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreateCustomer.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreateCustomer.php @@ -17,7 +17,9 @@ use App\Models\Client; use App\PaymentDrivers\AuthorizePaymentDriver; use net\authorize\api\contract\v1\CreateCustomerProfileRequest; use net\authorize\api\contract\v1\CustomerProfileType; +use net\authorize\api\contract\v1\GetCustomerProfileRequest; use net\authorize\api\controller\CreateCustomerProfileController; +use net\authorize\api\controller\GetCustomerProfileController; /** * Class BaseDriver. @@ -75,4 +77,45 @@ class AuthorizeCreateCustomer throw new GenericPaymentDriverFailure($message); } } + + public function get($profileIdRequested) + { + + error_reporting(E_ALL & ~E_DEPRECATED); + + $this->authorize->init(); + $request = new GetCustomerProfileRequest(); + $request->setMerchantAuthentication($this->authorize->merchant_authentication); + $request->setCustomerProfileId($profileIdRequested); + $controller = new GetCustomerProfileController($request); + $response = $controller->executeWithApiResponse($this->authorize->merchant_authentication); + + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + echo "GetCustomerProfile SUCCESS : " . "\n"; + $profileSelected = $response->getProfile(); + $paymentProfilesSelected = $profileSelected->getPaymentProfiles(); + echo "Profile Has " . count($paymentProfilesSelected). " Payment Profiles" . "\n"; + + if($response->getSubscriptionIds() != null) + { + if($response->getSubscriptionIds() != null) + { + + echo "List of subscriptions:"; + foreach($response->getSubscriptionIds() as $subscriptionid) + echo $subscriptionid . "\n"; + + } + } + } + else + { + echo "ERROR : GetCustomerProfile: Invalid response\n"; + $errorMessages = $response->getMessages()->getMessage(); + echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"; + } + + return $response; + } } From af523a63461c6b7aa5a8d8498735f6d5aba55a9d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 25 Jan 2021 23:16:43 +1100 Subject: [PATCH 2/2] detach payment method from authorize gateway --- .../ClientPortal/PaymentMethodController.php | 3 +- .../Authorize/AuthorizeCreateCustomer.php | 3 +- .../Authorize/AuthorizePaymentMethod.php | 35 +++++++++++++++++++ app/PaymentDrivers/AuthorizePaymentDriver.php | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index 186c38fefc41..1ed3c9c00453 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -151,7 +151,8 @@ class PaymentMethodController extends Controller event(new MethodDeleted($payment_method, auth('contact')->user()->company, Ninja::eventVars())); $payment_method->delete(); } catch (Exception $e) { - Log::error(json_encode($e)); + + nlog($e->getMessage()); return back(); } diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreateCustomer.php b/app/PaymentDrivers/Authorize/AuthorizeCreateCustomer.php index 1adfb93b9273..004f8bac26dd 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreateCustomer.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreateCustomer.php @@ -87,6 +87,7 @@ class AuthorizeCreateCustomer $request = new GetCustomerProfileRequest(); $request->setMerchantAuthentication($this->authorize->merchant_authentication); $request->setCustomerProfileId($profileIdRequested); + $controller = new GetCustomerProfileController($request); $response = $controller->executeWithApiResponse($this->authorize->merchant_authentication); @@ -105,7 +106,7 @@ class AuthorizeCreateCustomer echo "List of subscriptions:"; foreach($response->getSubscriptionIds() as $subscriptionid) echo $subscriptionid . "\n"; - + } } } diff --git a/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php b/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php index 05264768246f..f65501daf7aa 100644 --- a/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php +++ b/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php @@ -18,10 +18,12 @@ use App\PaymentDrivers\AuthorizePaymentDriver; use net\authorize\api\contract\v1\CreateCustomerPaymentProfileRequest; use net\authorize\api\contract\v1\CustomerAddressType; use net\authorize\api\contract\v1\CustomerPaymentProfileType; +use net\authorize\api\contract\v1\DeleteCustomerPaymentProfileRequest; use net\authorize\api\contract\v1\GetCustomerPaymentProfileRequest; use net\authorize\api\contract\v1\OpaqueDataType; use net\authorize\api\contract\v1\PaymentType; use net\authorize\api\controller\CreateCustomerPaymentProfileController; +use net\authorize\api\controller\DeleteCustomerPaymentProfileController; use net\authorize\api\controller\GetCustomerPaymentProfileController; use stdClass; @@ -246,4 +248,37 @@ class AuthorizePaymentMethod throw new GenericPaymentDriverFailure('Error communicating with Authorize.net'); } } + + public function deletePaymentProfile($gateway_customer_reference, $payment_profile_id) { + + error_reporting(E_ALL & ~E_DEPRECATED); + + $this->authorize->init(); + + // Set the transaction's refId + $refId = 'ref' . time(); + + // Use an existing payment profile ID for this Merchant name and Transaction key + + $request = new DeleteCustomerPaymentProfileRequest(); + $request->setMerchantAuthentication($this->authorize->merchant_authentication); + $request->setCustomerProfileId($gateway_customer_reference); + $request->setCustomerPaymentProfileId($payment_profile_id); + $controller = new DeleteCustomerPaymentProfileController($request); + + $response = $controller->executeWithApiResponse($this->authorize->mode()); + if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") ) + { + nlog("SUCCESS: Delete Customer Payment Profile SUCCESS :"); + } + else + { + nlog("ERROR : Delete Customer Payment Profile: Invalid response\n"); + $errorMessages = $response->getMessages()->getMessage(); + nlog("Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n"); + } + + return $response; + } + } diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index 06204a156384..a802e5d59712 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -156,6 +156,6 @@ class AuthorizePaymentDriver extends BaseDriver */ public function detach(ClientGatewayToken $token) { - // Authorize.net doesn't support this feature. + return (new AuthorizePaymentMethod($this))->deletePaymentProfile($token->gateway_customer_reference, $token->token); } }