lensmedia/symfony-ideal

"Private" 包用于处理 iDeal 交易

安装: 891

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

2.0.5 2024-01-18 14:19 UTC

This package is auto-updated.

Last update: 2024-09-21 09:57:42 UTC


README

创建 iDEAL 2 支付的基本包。

目前仅实现了基本的支付初始化/通知/状态调用。使用 brick/money (Money/Decimal/Currency) 处理货币值/货币相关事务。

该包主要由两部分组成,symfony 包的内容。以及一种未提取的独立库(https://github.com/lensmedia/symfony-ideal/tree/master/src/Ideal),用于所有来自 API 的请求/响应,我在其中运行。这可以在 symfony 之外使用。

配置

以下是从我们的 Rabobank 文档中的测试值。

lens_ideal:
    initiating_party_id: '002881'
    client: 'RaboiDEAL'
    base_url: 'https://routingservice-rabo.awltest.de/'
    public_key_path: '%kernel.project_dir%/config/certificates/TestCertificatesiDEAL.2.0.pem'
    private_key_path: '%kernel.project_dir%/config/certificates/TestCertificatesiDEAL.2.0.key'

    notifications:
        token: 'iDEAL2.0testnotificationtoken'

支付

// Random ID
$endToEndId = (string)(new Ulid());

// This bundle has a lib of classes for the data structure comparable to the open banking one.
$payment = new PaymentInitiationRequest();
$payment->paymentProduct[] = PaymentProduct::Ideal;

$basicPayment = new PaymentInitiationRequestBasic();
$basicPayment->endToEndId = $endToEndId;
$payment->commonPaymentData = $basicPayment;

$price = Money::of(IdealInterface::DEBUG_PRICE_COMPLETED, 'EUR');
$basicPayment->amount = Amount::create($price);
$basicPayment->remittanceInformation = '00004123';
$basicPayment->remittanceInformationStructured = new RemittanceInformationStructured();
$basicPayment->remittanceInformationStructured->reference = '00004123';

// Set up headers, see docs or PaymentArrayShapeTrait::PAYMENT_HEADERS
$headers = [
    // The return URL when the payment has been completed.
    'InitiatingPartyReturnUrl' => $this->generateUrl('ideal_completed', [
        'id' => $endToEndId,
    ], UrlGeneratorInterface::ABSOLUTE_URL),

    // Optional if you want to use the notification system.
    'InitiatingPartyNotificationUrl' => $this->generateUrl('ideal_notification', [
        'id' => $endToEndId,
    ], UrlGeneratorInterface::ABSOLUTE_URL),

    'Locale' => $request->getLocale(),
];

// Send payment initiation request.
$response = $ideal->payments->create($payment, headers: $headers);

// Redirect to bank.
return $this->redirect($response->links->redirectUrl->href);

状态

/** @var \Lens\Bundle\IdealBundle\Ideal\Data\PaymentDetailedInformation $response */
$response = $ideal->payments->status($paymentId);
  • 注意 paymentId 是在初始化请求中由银行返回的,它不是我们的端到端 ID 或任何东西。
  • 注意 paymentIdaspspPaymentId 不同,后者包含旧的理想交易 ID。这使得状态请求与之前的交易不兼容,因为您无法使用旧的 ID 进行查询。

通知

通知路由示例。

public function notification(
    IdealInterface $ideal,
    Request $request,
): Response {
    /** @var \Lens\Bundle\IdealBundle\Ideal\Data\PaymentDetailedInformation $data */
    $data = $ideal->payments->mapPaymentNotificationData($request->getContent());

    ...