Payment Gateway WechatPay

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
kuoyehs
Posts: 22
Joined: 09 Sep 2019, 03:01

Payment Gateway WechatPay

Post by kuoyehs » 09 Sep 2019, 04:13

I have a problem on new omnipay payment method. I have imported the ai-payments extension, the omnipay and the omnipay-wechatpay package. I have created a new payment service with omnipay.type = "WechatPay".

Image

When I select the payment method during checkout, and proceed to make the payment, I am getting the error message "The body parameter is required".

Image

Image

I try to add option "body", and have the same error message.

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: Payment Gateway WechatPay

Post by aimeos » 09 Sep 2019, 08:08

The WechatPay driver doesn't follow the Omnipay conventions for the field names.

Omnipay standard:

Code: Select all

$data = array(
	'language' => 'en',
	'transactionId' => '123',
	'amount' => '1.00',
	'currency' => 'CNY',
	'description' => 'The test order',
	'clientIp' => '127.0.0.1',
);
WechatPay driver:

Code: Select all

$order = [
    'body'              => 'The test order',
    'out_trade_no'      => date('YmdHis').mt_rand(1000, 9999),
    'total_fee'         => 1, //=0.01
    'spbill_create_ip'  => 'ip_address',
    'fee_type'          => 'CNY'
];
You should notify the author and if he doesn't want to change it (because of backwards compatibility), you should fork the driver and make it conform to Omnipay standards yourself.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: Payment Gateway WechatPay

Post by godadada@yahoo.com » 14 Jan 2022, 00:57

Has this issue been resolved?

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: Payment Gateway WechatPay

Post by aimeos » 14 Jan 2022, 08:06

This is nothing we can solve because it's not our code.
You can create a PR in the repo of the Wechat driver and propose the required changes.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: Payment Gateway WechatPay

Post by godadada@yahoo.com » 14 Jan 2022, 09:21

Thanks,

Any other wechat package that is compatible with Aimeos I can use?
Also, any suggestion on delivery service for Chinese customers?

Regards,

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: Payment Gateway WechatPay

Post by godadada@yahoo.com » 15 Jan 2022, 10:06

Does lokielse /omnipay-alipay conform to Omnipay standard?

Regards,

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: Payment Gateway WechatPay

Post by aimeos » 16 Jan 2022, 12:14

Unfortunately not because it's also using non-standard parameters:
https://github.com/lokielse/omnipay-glo ... y#purchase

The official Omnipay parameters are:
https://github.com/aimeoscom/ai-payment ... #L678-L683

You can extend from the MShop/Service/Provider/Payment/OmniPay class and overwrite the getData() method. If you return the parameter names as required by the driver, then it should work.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: Payment Gateway WechatPay

Post by godadada@yahoo.com » 17 Jan 2022, 06:50

Thanks for the reply.

pardon my rookie understanding and solution. Any help is appreciated.

ext/small-ext/lib/custom/src/MShop/Service/Provider/Payment/WechatPay.php

<?php

/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2015-2021
* @package MShop
* @subpackage Service
*/


namespace Aimeos\MShop\Service\Provider\Payment;

use Aimeos\MShop\Order\Item\Base as Status;


/**
* Payment provider for WechatPay.
*
* @package MShop
* @subpackage Service
*/
class WechatPay
extends \Aimeos\MShop\Service\Provider\Payment\OmniPay
implements \Aimeos\MShop\Service\Provider\Payment\Iface
{

/**
* Returns the data passed to the Omnipay library
*
* @param \Aimeos\MShop\Order\Item\Base\Iface $base Basket object
* @param string $orderid Unique order ID
* @param array $params Request parameter if available
* @return array Associative list of key/value pairs
*/
protected function getData( \Aimeos\MShop\Order\Item\Base\Iface $base, string $orderid, array $params ) : array
{
$data = parent::getData( $base, $orderid, $params );
$provider = parent::getProvider();

$data['body'] = $provider->getBody();
$data['out_trade_no'] = $provider->getOutTradeNo();
$data['total_fee'] = $provider->getTotalFee();
$data['spbill_create_ip'] = $provider->getSpbillCreateIp();
$data['fee_type'] = $provider->getFeeType();

return $data + $this->getPaymentUrls();
}
}
~

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: Payment Gateway WechatPay

Post by aimeos » 18 Jan 2022, 08:59

The correct code should be:

Code: Select all

protected function getData( \Aimeos\MShop\Order\Item\Base\Iface $base, string $orderid, array $params ) : array
{
	$data = parent::getData( $base, $orderid, $params );

	$data['body'] = sprintf( $this->context()->translate( 'mshop', 'Order %1$s' ), $orderid ),;
	$data['out_trade_no'] = $orderid;
	$data['fee_type'] = $base->locale()->getCurrencyId();
	$data['total_fee'] = $this->getAmount( $base->getPrice() ) * 100;
	$data['spbill_create_ip'] = $this->getValue( 'client.ipaddress' );

	return $data;
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

godadada@yahoo.com
Posts: 56
Joined: 15 Mar 2021, 01:03

Re: Payment Gateway WechatPay

Post by godadada@yahoo.com » 18 Jan 2022, 09:39

Much appreciated!

Post Reply