detach payment method from authorize gateway

This commit is contained in:
David Bomba 2021-01-25 23:16:43 +11:00
parent 64dfe1d6c3
commit af523a6346
4 changed files with 40 additions and 3 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

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

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