The CreatePayment class implements the RequestInterface and represents a payment creation request model. It contains information about the payment such as the amount, cart, currency, description, control, customer, billing, shipping, callback return URL, direct channel, channels, channel type, and referer.
amount- an object of theAmountclass representing the payment amount.currency- an optional object of theCurrencyclass representing the payment currency.description- an optional object of theDescriptionclass representing the payment description.control- an optional object of theControlclass representing the payment control.customer- an optional object of theCustomerclass representing the payment customer.billing- an optional object of theBillingclass representing the payment billing.shipping- an optional object of theShippingclass representing the payment shipping.cart- an array ofCartItemobjects representing the payment cart.returns- an optional object of theCallbackReturnUrlclass representing the payment callback return URL.directChannel- an optional object of theDirectChannelclass representing the payment direct channel.channels- an optional array ofChannelobjects representing the payment channels.channelType- an optional object of theChannelTypeclass representing the payment channel type.referer- an optional object of theRefererclass representing the payment referer.
__construct(Amount $amount, array $cart, ?ChannelType $channelType = null, ?Currency $currency = null, ?Description $description = null, ?Control $control = null, ?Customer $customer = null, ?Billing $billing = null, ?Shipping $shipping = null, ?CallbackReturnUrl $returns = null, ?DirectChannel $directChannel = null, ?array $channels = null, ?Referer $referer = null)- the constructor of the class that initializes its properties.toArray(): array- returns an array representation of the class properties.
$amount = new Amount(1000, 2);
$cart = [
new CartItem('Product 1', 500, 1),
new CartItem('Product 2', 500, 1),
];
$currency = new Currency('EUR');
$description = new Description('Payment for products');
$control = new Control('123456');
$customer = new Customer('John', 'Doe', 'john.doe@example.com');
$billing = new Billing('John', 'Doe', '123 Main St', 'Anytown', '12345', 'US', '1234567890');
$shipping = new Shipping('John', 'Doe', '123 Main St', 'Anytown', '12345', 'US', '1234567890');
$returns = new CallbackReturnUrl('https://example.com/callback');
$directChannel = new DirectChannel('web');
$channels = [
new Channel(Channel::VISA),
new Channel(Channel::MASTERCARD),
];
$channelType = new ChannelType(ChannelType::ECOMMERCE);
$referer = new Referer('https://example.com');
$request = new CreatePayment(
$amount,
$cart,
$channelType,
$currency,
$description,
$control,
$customer,
$billing,
$shipping,
$returns,
$directChannel,
$channels,
$referer
);
$requestData = $request->toArray();In this example, we create a new CreatePayment request object with all the required and optional properties initialized. We then call the toArray() method to get an array representation of the request data.