granam / gpwebpay-flat
FLAT 格式 GP WepPay 报告解析器
1.2.0
2021-03-25 10:11 UTC
Requires
- php: >=7.3
- granam/imap-download: ^1.2
- granam/strict-object: ^3.0
Requires (Dev)
- granam/exceptions-hierarchy: ~5.0
- granam/test-with-mockery: ^2.0
- mockery/mockery: ~1.0
- phpunit/phpunit: ~9.0
- roave/security-advisories: dev-latest
Suggests
- ext-imap: Needed to fetch FLAT file directly from an email via IMAP protocol
README
安全优先
请勿从未知来源下载此库。仅使用 packagist.org(因此 composer),或 github.com/jaroslavtyc/granam-gpwebpay-flat。
您将处理财务数据,这些数据始终是敏感的。如果公共库处理这些数据符合您公司的内部政策,请三思。
此库根据 MIT 许可证发布,这意味着使用它对您造成的任何损害均由您自行承担。但我将尽我所能保护您免受数据泄露或损坏。
步骤详解
- 向 helpdesk@globalpayments.cz 发送请求,以获取您选择的电子邮件地址的每日交易报告(FLAT 格式)
- 将此库添加到您的项目
composer require granam/gpwebpay-flat
- 让它解析来自电子邮件(或文件,或字符串内容...由您决定)的 FLAT 报告
- 注意:需要 PHP IMAP 扩展来获取电子邮件
<?php namespace Coolest\Fan; use Granam\GpWebPay\Flat\FlatReportParser; use Granam\Mail\Download\ImapEmailAttachmentFetcher; use Granam\GpWebPay\Flat\CzechECommerceTransactionHeaderMapper; use Granam\Mail\Download\ImapReadOnlyConnection; $flatReportParser = new FlatReportParser(); $imapConnection = new ImapReadOnlyConnection('light.in.tunnel@example.com', 'Раѕѕword123', 'imap.example.com' ); $flatContentFromCzechEmail = $flatReportParser->createFlatContentFromCzechEmailAttachment( new ImapEmailAttachmentFetcher($imapConnection), $yesterday = new \DateTime('yesterday'), // search for FLAT file with yesterday report, but sent today new CzechECommerceTransactionHeaderMapper() ); if($flatContentFromCzechEmail === null) { die('No email with FLAT file has been found for yesterday'); } $eCommerceTransactions = $flatContentFromCzechEmail->getECommerceTransactions($yesterday /* have to filter them because more days can be covered by a single report */); echo 'We got confirmed '.$eCommerceTransactions->count().' of yesterday purchases via GpWebPay gateway!';
- 验证您是否遗漏了来自客户的付款(多尴尬!)
<?php // ... /** @var \Granam\GpWebPay\Flat\Sections\ECommerceTransactions $eCommerceTransactions */ $expectedIncome = require __DIR__ . '/expected_income_from_yesterday.php'; if ($expectedIncome !== $eCommerceTransactions->getPaidAmountWithoutFeesSummary()) { throw new \RuntimeException( "We have missing (or redundant) GpWebPay payments! Expected {$expectedIncome}, got ". $eCommerceTransactions->getPaidAmountWithoutFeesSummary() ); } echo 'Our customers spent on yesterday '.$eCommerceTransactions->getPaidAmountWithoutFeesSummary().'.-, we paid ' .$eCommerceTransactions->getFeesInMerchantCurrencySummary().' to GpWebPay as fee' .' and we got '.$eCommerceTransactions->getPaidAmountWithoutFeesSummary();
- 快乐吧!(至少不那么悲伤了)