In Conekta, you need to create Orders and attach them the corresponding charge in order to receive payments.
LaravelConekta implements natural API methods to achieve this task.
We have two classes, Order and Product.
Order instances contain the data needed to send to Conekta.
Product objects, on the other hand, are intended to hold the information about the product’s data that the user is purchasing. The product instance, need 3 parameters in order to be created: The name of the product, the unit price (in cents) and the quantity.
To create a new Order, you can:
$order = $user->createOrder(); //Will return a new Order
Lenguaje del código: PHP (php)
Then, you can add as many products as you want:
use Danielmlozano\LaravelConekta\Product;
...
$order = $user->createOrder();
$order->addProduct(new Product("An awesome t-shirt", 25000, 1));
Lenguaje del código: PHP (php)
Then, indicate the payment method should be use to receive the charge:
$order->withPaymentMethod($user->paymentMethods()->first());
Lenguaje del código: PHP (php)
Or if you want to use the default payment method:
$order->withDefaultPaymentMethod();
Lenguaje del código: PHP (php)
And finally, you can perform the charge
$order->charge();
Lenguaje del código: PHP (php)
You can also chain the previous methods:
$payment = $user->createOrder()->addProduct($product)->addProduct($second_product)->withDefaultPaymentMethod()->charge();
Lenguaje del código: PHP (php)
The result of the charge method, is an instance of the object Payment, which is serializable and has the same __get method to retrive any Conekta\Order property needed.