How to get the frontend Configaration value from Payment 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!
How to get the frontend Configaration value from Payment provider?
I can not get frontend configuration attribute that provide in checkout page.
Aimeos laravel version: "aimeos/aimeos-laravel": "~2024.10",
Laravel: 11
php: 8.2
Environment: windows 10
I use it and the filed is showing in the checkout page perfectly
When checkout user can provide there phone number and BIC code but I can not get the value(data) of Phone and BIC inside the process method.
How can I get the value of Phone and BIC code inside the process method or anywhere in the payment provider ?
I tried like this but failed :
My full code is :
Aimeos laravel version: "aimeos/aimeos-laravel": "~2024.10",
Laravel: 11
php: 8.2
Environment: windows 10
I use it and the filed is showing in the checkout page perfectly
Code: Select all
private array $feConfig = array(
'aamarpay.mobile' => array(
'code' => 'aamarpay.mobile',
'internalcode'=> 'mobile',
'label'=> 'Phone',
'type'=> 'string',
'internaltype'=> 'string',
'default'=> '',
'required'=> true
),
'novalnetsepa.bic' => array(
'code' => 'novalnetsepa.bic',
'internalcode'=> 'bic',
'label'=> 'BIC code',
'type'=> 'string',
'internaltype'=> 'string',
'default'=> '',
'required'=> true
),
);
How can I get the value of Phone and BIC code inside the process method or anywhere in the payment provider ?
I tried like this but failed :
Code: Select all
$this->getConfigFE($order)['aamarpay.mobile']
Code: Select all
<?php
namespace Aimeos\MShop\Service\Provider\Payment;
use Illuminate\Support\Collection;
class AamarPay extends \Aimeos\MShop\Service\Provider\Payment\Base
implements \Aimeos\MShop\Service\Provider\Payment\Iface {
private array $beConfig = array(
'aamarpay.StoreID' => array(
'code' => 'aamarpay.StoreID',
'internalcode' => 'aamarpay.StoreID',
'label' => 'Aamarpay Store ID',
'type' => 'string',
'default' => '',
'required' => true,
),
'aamarpay.SignatureKey' => array(
'code' => 'aamarpay.SignatureKey',
'internalcode' => 'aamarpay.SignatureKey',
'label' => 'Aamarpay Signature Key',
'type' => 'string',
'default' => '',
'required' => true,
),
'aamarpay.testmode' => array(
'code' => 'aamarpay.testmode',
'internalcode' => 'aamarpay.testmode',
'label' => 'Test mode without payments',
'type' => 'bool',
'internaltype' => 'boolean',
'default' => '0',
'required' => true,
),
);
private array $feConfig = array(
'aamarpay.mobile' => array(
'code' => 'aamarpay.mobile',
'internalcode'=> 'mobile',
'label'=> 'Phone',
'type'=> 'string',
'internaltype'=> 'string',
'default'=> '',
'required'=> true
),
'novalnetsepa.bic' => array(
'code' => 'novalnetsepa.bic',
'internalcode'=> 'bic',
'label'=> 'BIC code',
'type'=> 'string',
'internaltype'=> 'string',
'default'=> '',
'required'=> true
),
);
/**
* Returns the configuration attribute definitions of the provider to generate a list of available fields and
* rules for the value of each field in the administration interface.
*
* @return array List of attribute definitions implementing \Aimeos\Base\Critera\Attribute\Iface
*/
public function getConfigBE() : array
{
return $this->getConfigItems( $this->beConfig );
}
/**
* Checks the backend configuration attributes for validity.
*
* @param array $attributes Attributes added by the shop owner in the administraton interface
* @return array An array with the attribute keys as key and an error message as values for all attributes that are
* known by the provider but aren't valid
*/
public function checkConfigBE( array $attributes ) : array
{
$errors = parent::checkConfigBE( $attributes );
return array_merge( $errors, $this->checkConfig( $this->beConfig, $attributes ) );
}
public function getConfigFE( \Aimeos\MShop\Order\Item\Iface $basket ) : array
{
$list = [];
$feconfig = $this->feConfig;
try
{
$service = $basket->getService( \Aimeos\MShop\Order\Item\Service\Base::TYPE_PAYMENT, 0 );
foreach( $service->getAttributeItems() as $item )
{
if( isset( $feconfig[$item->getCode()] ) ) {
$feconfig[$item->getCode()]['default'] = $item->getValue();
}
}
}
catch( \Aimeos\MShop\Order\Exception $e ) {; }
foreach( $feconfig as $key => $config ) {
$list[$key] = new \Aimeos\Base\Criteria\Attribute\Standard( $config );
}
return $list;
}
public function checkConfigFE( array $attributes ) : array
{
return $this->checkConfig( $this->feConfig, $attributes );
}
public function setConfigFE( \Aimeos\MShop\Order\Item\Service\Iface $orderServiceItem,
array $attributes ) : \Aimeos\MShop\Order\Item\Service\Iface
{
return $orderServiceItem->addAttributeItems( $this->attributes( $attributes, 'payment' ) );
}
public function getFullUrl() {
return ($this->getConfigValue(array('aamarpay.testmode')) === true) ? 'https://sandbox.aamarpay.com/jsonpost.php' : 'https://secure.aamarpay.com/jsonpost.php';
}
public function payRequest(array $param) {
$data = json_encode($param);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->getFullUrl(),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>$data,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
public function process( \Aimeos\MShop\Order\Item\Iface $order,
array $params = [] ) : ?\Aimeos\MShop\Common\Helper\Form\Iface
{
//$total = $order->getPrice()->getValue() + $order->getPrice()->getCosts();
$storeid = $this->getConfigValue(array('aamarpay.StoreID'));
$SignatureKey = $this->getConfigValue(array('aamarpay.SignatureKey'));
if( ( $addresses = $order->getAddress( \Aimeos\MShop\Order\Item\Address\Base::TYPE_DELIVERY ) ) === [] ) {
$addresses = $order->getAddress( \Aimeos\MShop\Order\Item\Address\Base::TYPE_PAYMENT );
}
$addresses = $order->getAddress( type: \Aimeos\MShop\Order\Item\Address\Base::TYPE_PAYMENT );
$addr = current( $order->getAddress( 'payment' ) );
$data = [
'store_id' => $storeid,
'signature_key' => $SignatureKey,
'tran_id' => $order->getId(),
'currency' => $order->getPrice()->getCurrencyId(),
'desc' => 'Name: ' . $addr->getFirstName() . ' ' . $addr->getLastName() . ' Order id: ' . $order->getId(),
'cus_name' => $addr->getFirstName() . ' ' . $addr->getLastName(),
'cus_email' => $addr->getEmail(),
'cus_phone' => $this->getConfigFE($order)['aamarpay.mobile'],
'success_url' => $this->getConfigValue( 'payment.url-success' ),
'fail_url' => $this->getConfigValue( 'payment.url-success' ),
'cancel_url' => $this->getConfigValue( 'payment.url-success' ),
'type' => 'json'
];
$status = \Aimeos\MShop\Order\Item\Base::PAY_RECEIVED;
$order->setStatusPayment( $status );
$this->save( $order );
return parent::process( $order, $params );
}
}
Re: How to get the frontend Configaration value from Payment provider?
The values are stored as order service attributes in the basket in your setConfigFE() method. You can get that values later using:
There are more methods for retrieving service attributes available:
https://github.com/aimeos/aimeos-core/b ... #L151-L175
Code: Select all
if($service = current($order->getService('payment'))) {
$attrItems = $service->getAttributeItems();
}
https://github.com/aimeos/aimeos-core/b ... #L151-L175
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
