fraganzas/omnipago

omnipay中的euPago集成

dev-master 2023-10-10 23:20 UTC

This package is auto-updated.

Last update: 2024-09-11 01:21:13 UTC


README

这是omnipay支付处理库的euPago解决方案

Eupago是葡萄牙的一个支付网关,提供多种支付方式。要使用它,您需要在euPago网站上创建一个账户。安装并配置后,您可以使用我们API的所有功能。

安装

composer require league/omnipay:^3 fraganzas/omnipay

实现的支付方式

  • 多银行(Multibanco) - 创建带有和没有起始/结束日期、最小/最大金额支持的MB参考(只需设置相应的参数)
  • MBWay - MBWay支付系统
  • PayShop
  • Pagaqui

示例

创建Multibanco参考

$gateway = Omnipay::create('Eupago_Multibanco');

// required fields
$gateway->setApiKey('xxx-xxx-xxx-xxx');
$gateway->setCurrency('EUR');
$gateway->setTransactionId('xxxxx');
// Optionally with start/end date
$gateway->setStartDate(new \DateTime);
$gateway->setEndDate((new \DateTime)->modify('48 hours'));

$response = $gateway->purchase(['amount' => '10.00'])->send();

if ($response->isSuccessful()) {
	// return the euPago api response with payment credentials
	// see src/Message/MultibancoResponse.php methods for more information
	$paymentData = $response->getData();

	// return the Transaction Reference
	// the transaction Reference is required for call the status of payment, you should store them in your "orders" table related database
	$referenceId = $response->getTransactionReference();
} else {
    // Transaction creation failed: display message to customer
    echo $response->getMessage();
}

检查Multibanco参考状态

$gateway = Omnipay::create('Eupago_Multibanco');

// The transaction reference is required
$paymentStatus = $gateway->checkStatus([
	'transactionReference' => 'xxxxxx'
])->send();

if ($paymentStatus->isPaid()) {
    // payment was successful: update database
} else {
    // payment failed: display message to customer
    echo $paymentStatus->getMessage();
}

创建MBWay参考

$gateway = Omnipay::create('Eupago_MBWay');

// Campos obrigatórios
$gateway->setApiKey('xxxx-xxxx-xxx-xxx'); //ver aqui: replica.eupago.pt/clientes/contas/fichas
$gateway->setCurrency('EUR');
$gateway->setTransactionId('1');
$gateway->setAlias('910000000'); //número tlm cliente
// Campos opcionais
$gateway->setStartDate(new \DateTime);
$gateway->setEndDate((new \DateTime)->modify('48 hours')); //limite

$response = $gateway->purchase(['amount' => '10.00'])->send();

if ($response->isSuccessful()) {
// return the euPago api response with payment credentials
// see src/Message/MultibancoResponse.php methods for more information
$paymentData = $response->getData();

// return the Transaction Reference
// the transaction Reference is required for call the status of payment, you should store them in your "orders" table related database
$referenceId = $response->getTransactionReference();

//Exemplo de resposta bem sucedida
/*
+"sucesso": true
+"referencia": "xxxx"
+"valor": 10.0
+"estado": 0
+"resposta": "OK"
+"alias": "351#910000000"
*/

} 
else {
// Transaction creation failed: display message to customer
echo $response->getMessage();
}

```

检查Multibanco参考状态

$gateway = Omnipay::create('Eupago_MBWay');

// The transaction reference is required
$paymentStatus = $gateway->checkStatus([
'transactionReference' => $request->referenceID
])->send();

if ($paymentStatus->isPaid()) {
//Referência paga
} else {
/*
 * Valor de "$paymentStatus->getMessage();" pode ser:
 * "OK" : Referência existe mas não está pago
 * "Referência Inexistente." : Referência não existe.
 */
echo $paymentStatus->getMessage();
}