public function StoredOffsiteRedirect::createPaymentMethod in Commerce Core 8.2
1 call to StoredOffsiteRedirect::createPaymentMethod()
- StoredOffsiteRedirect::onReturn in modules/
payment_example/ src/ Plugin/ Commerce/ PaymentGateway/ StoredOffsiteRedirect.php - Processes the "return" request.
File
- modules/
payment_example/ src/ Plugin/ Commerce/ PaymentGateway/ StoredOffsiteRedirect.php, line 92
Class
- StoredOffsiteRedirect
- Provides an example offsite payment gateway with stored payment methods.
Namespace
Drupal\commerce_payment_example\Plugin\Commerce\PaymentGatewayCode
public function createPaymentMethod(PaymentMethodInterface $payment_method, Request $request) {
// Off-site gateways often can created stored customer profiles or payment
// references from a processed transaction. A payment gateway would perform
// an API action to generate the payment method reference on the gateway
// here and then save it as a payment method.
$payment_method->card_type = 'visa';
$payment_method->card_number = '1111';
$payment_method->card_exp_month = '12';
$payment_method->card_exp_year = '26';
$expires = CreditCard::calculateExpirationTimestamp($payment_method->card_exp_month->value, $payment_method->card_exp_year->value);
$payment_method
->setExpiresTime($expires);
$payment_method
->setRemoteId('1234');
$payment_method
->save();
}