public function Stripe::deletePaymentMethod in Commerce Stripe 8
Deletes the given payment method.
Both the entity and the remote record are deleted.
Parameters
\Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method: The payment method.
Throws
\Drupal\commerce_payment\Exception\PaymentGatewayException Thrown when the transaction fails for any reason.
Overrides SupportsStoredPaymentMethodsInterface::deletePaymentMethod
1 call to Stripe::deletePaymentMethod()
- Stripe::createPayment in src/
Plugin/ Commerce/ PaymentGateway/ Stripe.php - Creates a payment.
File
- src/
Plugin/ Commerce/ PaymentGateway/ Stripe.php, line 415
Class
- Stripe
- Provides the Stripe payment gateway.
Namespace
Drupal\commerce_stripe\Plugin\Commerce\PaymentGatewayCode
public function deletePaymentMethod(PaymentMethodInterface $payment_method) {
// Delete the remote record.
$payment_method_remote_id = $payment_method
->getRemoteId();
try {
$remote_payment_method = PaymentMethod::retrieve($payment_method_remote_id);
if ($remote_payment_method->customer) {
$remote_payment_method
->detach();
}
} catch (ApiErrorException $e) {
ErrorHelper::handleException($e);
}
$payment_method
->delete();
}