Save values from payment extern provider
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 8
- Joined: 08 Sep 2017, 17:20
Save values from payment extern provider
In a new payment provider, I call an API that is processed in "Process ()" method, and it results in a json that I must show on the payment confirmation screen. My question is: How do I save that result in the database to call it in the confirmation of purchase?
Type: Laravel 5.3
Aimeos Version: 2017.07.10
PHP: 7.0
Type: Laravel 5.3
Aimeos Version: 2017.07.10
PHP: 7.0
Re: Save values from payment extern provider
You can use the order base service attributes to store arbitrary values and you can fetch and display that in the confirmation page afterwards:
https://aimeos.org/api/latest/class-Aim ... Iface.html
https://aimeos.org/api/latest/class-Aim ... Iface.html
Code: Select all
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/service/attribute' );
$attrItem = $manager->createItem()->setType( '<yourtype>' )->setCode( '<yourcode>' )->setValue( '<json>' );
$service = $basket->getService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT, '<servicecode>' );
$service->setAttributeItem( $attrItem );
// at confirmation page
$json = $service->getAttribute( '<yourcode>', '<yourtype' );
https://aimeos.org/api/latest/class-Aim ... Iface.html
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Posts: 8
- Joined: 08 Sep 2017, 17:20
Re: Save values from payment extern provider
do the implementation according to your explanation, but when I consult in the database, nothing appears to me, what is done there?
my code is:
my code is:
Code: Select all
public function process( \Aimeos\MShop\Order\Item\Iface $order, array $params = array() )
{
$parts = \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ADDRESS;
$parts |= \Aimeos\MShop\Order\Manager\Base\Base::PARTS_PRODUCT;
$parts |= \Aimeos\MShop\Order\Manager\Base\Base::PARTS_SERVICE;
$orderbase = $this->getOrderBase( $order->getBaseId(), $parts );
$envio = $orderbase->getService(\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_DELIVERY);
$productos = $orderbase->getProducts();
$addressClient = $orderbase->getAddress(\Aimeos\MShop\Order\Item\Base\Address\Base::TYPE_PAYMENT);
$datosdir = $addressClient->toArray();
$nombre = $datosdir["order.base.address.firstname"] . " " . $datosdir["order.base.address.lastname"];
$estadoId = $datosdir["order.base.address.state"];
$estadoName = $this->estados[$estadoId];
$cargosEnvio = intval($envio->getPrice()->getValue());
$cargosEnvioCost = intval($envio->getPrice()->getCosts());
$cargosEnvioTotal = $cargosEnvio + $cargosEnvioCost;
$jsonprod = [];
foreach ($productos as $prod) {
$todo = $prod->toArray();
$precio = intval($todo["order.base.product.price"]);
$costo = intval($todo["order.base.product.costs"]);
$totalprod = $precio + $costo;
array_push($jsonprod, [
"description" => "idcode: " . $prod->getId(),
"name" => $prod->getName(),
"quantity" => $prod->getQuantity(),
"unit_price" => $totalprod
]);
}
if(!empty($datosdir["order.base.address.address3"])){
$interior = $datosdir["order.base.address.address3"];
}
$jsonroot = [
"currency" => "MXN",
"customer_info" => [
"name" => $nombre,
"email" => $datosdir["order.base.address.email"],
"phone" => $datosdir["order.base.address.telephone"]
],
"shipping_contact" => [
"address" => [
"city" => $datosdir["order.base.address.city"],
"country" => $datosdir["order.base.address.countryid"],
"postal_code" => $datosdir["order.base.address.postal"],
"state" => $estadoName,
"street1" => $datosdir["order.base.address.address1"],
"street2" => "Interior " . $datosdir["order.base.address.address3"] . ", Colonia " . $datosdir["order.base.address.address2"]
],
"phone" => $datosdir["order.base.address.telephone"],
"receiver" => $nombre,
],
"shipping_lines" => [
[
"amount" => $cargosEnvioTotal,
"carrier" => $envio->getCode(), //buscar el nombre del carrier
"method" => $envio->getType()
]
],
"line_items" => $jsonprod,
"charges" => [
[
"payment_method" => [
"type" => "oxxo_cash",
]
]
]
];
try{
$cliente = new \GuzzleHttp\Client();
$res = $cliente->request('POST', 'some.mx/create', [
"json" => $jsonroot
]);
if($res->getStatusCode() == "200"){
$datos = json_decode($res->getBody());
$dataorden = $datos->data->order->charges->data->{'0'};
if($datos->errors){
throw new \Aimeos\MShop\Service\Exception( sprintf( $datos->data[0]->message . " - " . $datos->data[0]->debug_message . " - Codigo de error: " . $datos->data[0]->code ) );
} else{
$OxxoRef = [
"Reference" => $dataorden->payment_method->reference,
"BarcodeImg" => $dataorden->payment_method->barcode_url,
"Expire" => $dataorden->payment_method->expires_at,
"Total" => '$' . $dataorden->amount . " " . $dataorden->currency
];
$otherorderbase = $this->getOrderBase( $order->getBaseId());
//$otherservice = $otherorderbase->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT);
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base/service/attribute' );
//dd($manager->getType());
$itemPay = $manager->createItem()->setType('oxxo')->setcode('Reference')->setValue($dataorden->payment_method->reference);
//dd($OxxoRef);
//dd($order);
$service = $otherorderbase->getService( \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT, 'oxxo');
$service->setAttributeItem( $itemPay );
$status = \Aimeos\MShop\Order\Item\Base::PAY_PENDING;
$order->setPaymentStatus( $status );
//$serviceItem = $orderbase->getService(\Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_PAYMENT);
//$this->setAttributes($otherservice, $OxxoRef, 'payment/oxxo');
$this->saveOrder( $order );
}
} else{
throw new \Aimeos\MShop\Service\Exception( sprintf( $res->getMessage() + $res->getData() ) );
}
}
catch(\GuzzleHttp\Exception\RequestException $e){
throw new \Aimeos\MShop\Service\Exception( sprintf( $e->getMessage() ) );
}
catch(\GuzzleHttp\Exception\ConnectException $e){
throw new \Aimeos\MShop\Service\Exception( sprintf( $e->getMessage() ) );
}
catch(\GuzzleHttp\Exception\TransferException $e){
throw new \Aimeos\MShop\Service\Exception( sprintf( $e->getMessage() ) );
}
catch(\GuzzleHttp\Exception\ClientException $e){
throw new \Aimeos\MShop\Service\Exception( sprintf( $e->getMessage() ) );
}
return parent::process( $order, $params );
}
Re: Save values from payment extern provider
You have to save the modified basket too (the second parameter is optional):
Code: Select all
$this->saveOrderBase($otherorderbase, \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE);
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star