1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00

Merge pull request #4759 from turbo124/v5-develop

Delete payment profile from authorize.net gateway when detaching from AP
This commit is contained in:
David Bomba 2021-01-25 23:27:39 +11:00 committed by GitHub
commit 53e7ccbea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 2 deletions

View File

@ -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();
}

View File

@ -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,46 @@ 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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}