Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add apple pay partial invoice #241

Open
wants to merge 1 commit into
base: 4.0.9-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions Gateway/Response/ApplePay/VaultDetailsHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Braintree\Gateway\Response\ApplePay;

use Braintree\Transaction;
use DateInterval;
use DateTime;
use DateTimeZone;
use Exception;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Payment\Gateway\Response\HandlerInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class VaultDetailsHandler extends \Magento\Braintree\Gateway\Response\Handler implements HandlerInterface
{
/**
* @inheritdoc
*/
public function handle(array $handlingSubject, array $response)
{
$paymentDO = $this->subjectReader->readPayment($handlingSubject);
$transaction = $this->subjectReader->readTransaction($response);
$payment = $paymentDO->getPayment();

// add vault payment token entity to extension attributes
$paymentToken = $this->getVaultPaymentToken($transaction);
if (null !== $paymentToken) {
$extensionAttributes = $this->getExtensionAttributes($payment);
$extensionAttributes->setVaultPaymentToken($paymentToken);
}
}

/**
* Get vault payment token entity
*
* @param Transaction $transaction
* @return PaymentTokenInterface|null
* @throws InputException
* @throws NoSuchEntityException
*/
protected function getVaultPaymentToken(Transaction $transaction)
{
// Check token existing in gateway response
$token = $transaction->creditCardDetails->token;
if (empty($token)) {
return null;
}

/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->paymentTokenFactory->create();
$paymentToken->setGatewayToken($token);


return $paymentToken;
}
}
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<can_use_checkout>1</can_use_checkout>
<can_authorize>1</can_authorize>
<can_capture>1</can_capture>
<can_capture_partial>0</can_capture_partial>
<can_capture_partial>1</can_capture_partial>
<can_refund>1</can_refund>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_void>1</can_void>
Expand Down
9 changes: 9 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@
<item name="authorize" xsi:type="string">BraintreeApplePayAuthorizeCommand</item>
<item name="sale" xsi:type="string">BraintreeApplePaySaleCommand</item>
<item name="capture" xsi:type="string">BraintreeApplePayCaptureStrategyCommand</item>
<item name="vault_capture" xsi:type="string">BraintreeVaultCaptureCommand</item>
<item name="settlement" xsi:type="string">BraintreeCaptureCommand</item>
<item name="void" xsi:type="string">BraintreeVoidCommand</item>
<item name="refund" xsi:type="string">BraintreeRefundCommand</item>
Expand All @@ -686,12 +687,19 @@
<argument name="validator" xsi:type="object">Magento\Braintree\Gateway\Validator\ResponseValidator</argument>
</arguments>
</virtualType>
<!-- Value handlers infrastructure -->
<type name="Magento\Braintree\Gateway\Response\ApplePay\VaultDetailsHandler">
<arguments>
<argument name="paymentTokenFactory" xsi:type="object">Magento\Vault\Model\CreditCardTokenFactory</argument>
</arguments>
</type>
<virtualType name="BraintreeApplePayAuthorizationHandler" type="Magento\Payment\Gateway\Response\HandlerChain">
<arguments>
<argument name="handlers" xsi:type="array">
<item name="payment_details" xsi:type="string">Magento\Braintree\Model\ApplePay\PaymentDetailsHandler</item>
<item name="card_details" xsi:type="string">Magento\Braintree\Gateway\Response\CardDetailsHandler</item>
<item name="txn_id" xsi:type="string">Magento\Braintree\Gateway\Response\TransactionIdHandler</item>
<item name="vault_details" xsi:type="string">Magento\Braintree\Gateway\Response\ApplePay\VaultDetailsHandler</item>
</argument>
</arguments>
</virtualType>
Expand All @@ -701,6 +709,7 @@
<item name="customer" xsi:type="string">Magento\Braintree\Gateway\Request\CustomerDataBuilder</item>
<item name="payment" xsi:type="string">Magento\Braintree\Gateway\Request\PaymentDataBuilder</item>
<item name="channel" xsi:type="string">Magento\Braintree\Gateway\Request\ChannelDataBuilder</item>
<item name="vault" xsi:type="string">Magento\Braintree\Gateway\Request\VaultDataBuilder</item>
<item name="address" xsi:type="string">Magento\Braintree\Gateway\Request\AddressDataBuilder</item>
<item name="dynamic_descriptor" xsi:type="string">Magento\Braintree\Gateway\Request\DescriptorDataBuilder</item>
<item name="level_2_3_processing" xsi:type="string">Magento\Braintree\Gateway\Request\Level23ProcessingDataBuilder</item>
Expand Down