Skip to content

Commit

Permalink
ACP-3558 Merchant payment expense support. (#17)
Browse files Browse the repository at this point in the history
* ACP-3558 Merchant payment expense support.

* ACP-3558: Fixed the Spryker CV.
  • Loading branch information
abitskil authored Sep 5, 2024
1 parent eb3bba9 commit c56ff8a
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 87 deletions.
37 changes: 37 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Define the line ending behavior of the different file extensions
# Set the default behavior, in case people don't have core.autocrlf set.
* text text=auto eol=lf

*.php diff=php

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.gif binary
*.jpeg binary
*.zip binary
*.phar binary
*.ttf binary
*.woff binary
*.woff2 binary
*.eot binary
*.ico binary
*.mo binary
*.pdf binary
*.xsd binary
*.exe binary

# Remove files for archives generated using `git archive`
dependency.json export-ignore
phpstan.json export-ignore
phpstan.neon export-ignore
psalm-report.json export-ignore linguist-generated=true
tooling.yml export-ignore
.coveralls.yml export-ignore
.travis.yml export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
architecture-baseline.json export-ignore

.github/ export-ignore
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AppPayment Package
# AppPayment Module
[![Latest Stable Version](https://poser.pugx.org/spryker/app-payment/v/stable.svg)](https://packagist.org/packages/spryker/app-payment)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BF.svg)](https://php.net/)

Expand Down
1 change: 1 addition & 0 deletions architecture-baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"setup": "tests/bin/console app-payment:setup && tests/bin/console transfer:generate && tests/bin/console transfer:databuilder:generate && tests/bin/console dev:ide-auto-completion:zed:generate && tests/bin/console dev:ide-auto-completion:glue:generate && tests/bin/console propel:install && vendor/bin/codecept build",
"cs-check": "phpcs -p src/ tests/",
"cs-fix": "phpcbf -p src/ tests/",
"stan": "phpstan analyze src/Spryker/",
"stan": "phpstan analyze src/Spryker/ --memory-limit=1G",
"test": "codecept build && codecept run",
"test-cover": "codecept build && codecept run --coverage-xml",
"test-cover-html": "codecept build && codecept run --coverage-html",
Expand All @@ -81,7 +81,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "1.0.x-dev"
"dev-master": "2.0.x-dev"
}
},
"config": {
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: 8
ignoreErrors:
- '#Call to an undefined method Spryker\\Shared\\Kernel\\Transfer\\AbstractTransfer::getMessageAttributesOrFail\(\)#'
- '#Call to method appPayment\(\) on an unknown class Generated\\GlueBackend\\Ide\\AutoCompletion.#'
- '#Call to an undefined method Spryker\\Zed\\AppPayment\\Dependency\\Plugin\\AppPaymentPlatformPluginInterface::transferPayments\(\).#'
- '#Method Spryker\\Zed\\AppPayment\\Business\\Payment\\AppConfig\\AppConfigLoader::loadAppConfig\(\) should return Generated\\Shared\\Transfer\\AppConfigTransfer but returns Spryker\\Shared\\Kernel\\Transfer\\TransferInterface.#'
- '#Method Spryker\\Zed\\AppKernel\\Business\\AppKernelFacadeInterface::getConfig\(\) invoked with 2 parameters, 1 required.#'
6 changes: 6 additions & 0 deletions psalm-report.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function generateTransfersResponseContent(PaymentTransmissionsResponse
'failureMessage' => $paymentTransmission->getMessage(),
'merchantReference' => $paymentTransmission->getMerchantReference(),
'orderReference' => $paymentTransmission->getOrderReference(),
'orderItems' => $this->formatOrderItemsForTransferResponse($paymentTransmission->getOrderItems()),
'paymentTransmissionItems' => $this->formatPaymentTransmissionItemsForTransferResponse($paymentTransmission->getPaymentTransmissionItems()),
'amount' => $paymentTransmission->getAmount(),
'transferId' => $paymentTransmission->getTransferId(), // Return the transfer identifier as transaction id to be known on the Tenant side. May be empty in case oif a failure
];
Expand All @@ -85,23 +85,22 @@ protected function generateTransfersResponseContent(PaymentTransmissionsResponse
}

/**
* @param \ArrayObject<int, \Generated\Shared\Transfer\OrderItemTransfer> $arrayObject
* @param \ArrayObject<int, (\Generated\Shared\Transfer\OrderItemTransfer | \Generated\Shared\Transfer\PaymentTransmissionItemTransfer)> $arrayObject
*
* @return array<int, array<string, string|null>>
*/
protected function formatOrderItemsForTransferResponse(ArrayObject $arrayObject): array
protected function formatPaymentTransmissionItemsForTransferResponse(ArrayObject $arrayObject): array
{
$orderItemsData = [];

foreach ($arrayObject as $orderItem) {
$orderItemsData[] = [
'merchantReference' => $orderItem->getMerchantReferenceOrFail(),
'orderReference' => $orderItem->getOrderReferenceOrFail(),
'itemReference' => $orderItem->getItemReferenceOrFail(),
'amount' => $orderItem->getAmountOrFail(),
$paymentTransmissionItemsData = [];
foreach ($arrayObject as $paymentTransmissionItem) {
$paymentTransmissionItemsData[] = [
'merchantReference' => $paymentTransmissionItem->getMerchantReferenceOrFail(),
'orderReference' => $paymentTransmissionItem->getOrderReferenceOrFail(),
'itemReference' => $paymentTransmissionItem->getItemReferenceOrFail(),
'amount' => $paymentTransmissionItem->getAmountOrFail(),
];
}

return $orderItemsData;
return $paymentTransmissionItemsData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<property name="tenantIdentifier" type="string"/>
<property name="transactionId" type="string"/>
<property name="transferId" type="string"/>
<property name="orderItems" type="OrderItem[]" singular="orderItem"/>
<property name="paymentTransmissions" type="PaymentTransmission[]" singular="paymentTransmission"/>
<property name="paymentTransmissionItems" type="PaymentTransmissionItem[]" singular="paymentTransmissionItem"/>
</transfer>

<transfer name="OrderItem" strict="true">
Expand All @@ -24,6 +24,15 @@
<property name="amount" type="string" description="Amount in lowest denominator (cents, YEN). When negative money has to be refunded, when positive money has to be transferred."/>
</transfer>

<transfer name="PaymentTransmissionItem">
<property name="transferId" type="string" description="The ID returned from the Platform implementation"/>
<property name="type" type="string" description="Indicates whether the item is an order item or an order expense. Can be 'order-item', 'order-expense', or any additional type."/>
<property name="merchantReference" type="string"/>
<property name="orderReference" type="string"/>
<property name="itemReference" type="string" description="UUID of the sales_order_item or spy_sales_expense"/>
<property name="amount" type="string" description="Amount in lowest denominator (cents, YEN). When negative money has to be refunded, when positive money has to be transferred."/>
</transfer>

<transfer name="PaymentTransmissionsResponse" strict="true">
<property name="message" type="string"/>
<property name="paymentTransmissions" type="PaymentTransmission[]" singular="paymentTransmission"/>
Expand All @@ -39,7 +48,7 @@
<property name="merchantReference" type="string"/>
<property name="orderReference" type="string"/>
<property name="itemReferences" type="array" singular="itemReference" description="UUIDs of the sales_order_item(s)"/>
<property name="orderItems" type="OrderItem[]" singular="orderItem"/>
<property name="paymentTransmissionItems" type="PaymentTransmissionItem[]" singular="paymentTransmissionItem"/>
<property name="amount" type="string" description="Amount in lowest denominator (cents, YEN). When negative money has to be refunded, when positive money has to be transferred."/>
<property name="payment" type="Payment"/>
</transfer>
Expand Down
5 changes: 5 additions & 0 deletions src/Spryker/Zed/AppPayment/Business/AppPaymentFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public function deletePaymentCollection(
$this->getEntityManager()->deletePaymentCollection($paymentCollectionDeleteCriteriaTransfer);
}

/**
* {@inheritDoc}
*
* @api
*/
public function transferPayments(PaymentTransmissionsRequestTransfer $paymentTransmissionsRequestTransfer): PaymentTransmissionsResponseTransfer
{
return $this->getFactory()->createPayment()->transferPayments($paymentTransmissionsRequestTransfer);
Expand Down
Loading

0 comments on commit c56ff8a

Please sign in to comment.