public function PurchaseOrderGateway::createPaymentMethod in Commerce Purchase Order 8
Creates a payment method with the given payment details.
Parameters
\Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method: The payment method.
array $payment_details: The gateway-specific payment details provided by the payment method form for on-site gateways, or the incoming request for off-site gateways.
Throws
\Drupal\commerce_payment\Exception\PaymentGatewayException Thrown when the transaction fails for any reason.
Overrides SupportsCreatingPaymentMethodsInterface::createPaymentMethod
File
- src/
Plugin/ Commerce/ PaymentGateway/ PurchaseOrderGateway.php, line 187
Class
- PurchaseOrderGateway
- Provides the On-site payment gateway.
Namespace
Drupal\commerce_purchase_order\Plugin\Commerce\PaymentGatewayCode
public function createPaymentMethod(PaymentMethodInterface $payment_method, array $payment_details) {
$required_keys = [
'number',
];
foreach ($required_keys as $required_key) {
if (empty($payment_details[$required_key])) {
throw new \InvalidArgumentException(sprintf('$payment_details must contain the %s key.', $required_key));
}
}
// Not re-usable because we will store the PO number in the method.
$payment_method
->setReusable(FALSE);
$payment_method->po_number = $payment_details['number'];
$payment_method
->setExpiresTime(strtotime("+60 day"));
$payment_method
->save();
}