/** * @inheritdoc */ public function handle(array $handlingSubject, array $response) { $paymentDO = $this->subjectReader->readPayment($handlingSubject); /** * @TODO after changes in sales module should be refactored for new interfaces */ /** @var OrderPaymentInterface $payment */ $payment = $paymentDO->getPayment(); ContextHelper::assertOrderPayment($payment); /** @var Transaction $transaction */ $transaction = $this->subjectReader->readTransaction($response); if ($payment->hasAdditionalInformation(self::LIABILITY_SHIFTED)) { // remove 3d secure details for reorder $payment->unsAdditionalInformation(self::LIABILITY_SHIFTED); $payment->unsAdditionalInformation(self::LIABILITY_SHIFT_POSSIBLE); } if (empty($transaction->threeDSecureInfo)) { return; } /** @var \Braintree\ThreeDSecureInfo $info */ $info = $transaction->threeDSecureInfo; $payment->setAdditionalInformation(self::LIABILITY_SHIFTED, $info->liabilityShifted ? 'Yes' : 'No'); $shiftPossible = $info->liabilityShiftPossible ? 'Yes' : 'No'; $payment->setAdditionalInformation(self::LIABILITY_SHIFT_POSSIBLE, $shiftPossible); }
/** * @inheritdoc */ public function build(array $buildSubject) { $paymentDO = $this->subjectReader->readPayment($buildSubject); $order = $paymentDO->getOrder(); $billingAddress = $order->getBillingAddress(); return [self::CUSTOMER => [self::FIRST_NAME => $billingAddress->getFirstname(), self::LAST_NAME => $billingAddress->getLastname(), self::COMPANY => $billingAddress->getCompany(), self::PHONE => $billingAddress->getTelephone(), self::EMAIL => $billingAddress->getEmail()]]; }
/** * Builds ENV request * * @param array $buildSubject * @return array */ public function build(array $buildSubject) { $paymentDO = $this->subjectReader->readPayment($buildSubject); /** @var Payment $payment */ $payment = $paymentDO->getPayment(); return ['transaction_id' => $payment->getParentTransactionId() ?: $payment->getLastTransId()]; }
/** * @inheritdoc */ public function build(array $buildSubject) { $paymentDO = $this->subjectReader->readPayment($buildSubject); $payment = $paymentDO->getPayment(); $extensionAttributes = $payment->getExtensionAttributes(); $paymentToken = $extensionAttributes->getVaultPaymentToken(); return ['amount' => $this->formatPrice($this->subjectReader->readAmount($buildSubject)), 'paymentMethodToken' => $paymentToken->getGatewayToken()]; }
/** * Run test for validate method * * @param array $validationSubject * @param bool $isValid * @param Phrase[] $messages * @return void * * @dataProvider dataProviderTestValidate */ public function testValidate(array $validationSubject, $isValid, $messages) { /** @var ResultInterface|\PHPUnit_Framework_MockObject_MockObject $resultMock */ $resultMock = $this->getMock(ResultInterface::class); $this->subjectReaderMock->expects(self::once())->method('readResponseObject')->with($validationSubject)->willReturn($validationSubject['response']['object']); $this->resultInterfaceFactoryMock->expects(self::once())->method('create')->with(['isValid' => $isValid, 'failsDescription' => $messages])->willReturn($resultMock); $actualMock = $this->responseValidator->validate($validationSubject); self::assertEquals($resultMock, $actualMock); }
/** * @param array $billingData * @param array $expectedResult * * @dataProvider dataProviderBuild */ public function testBuild($billingData, $expectedResult) { $billingMock = $this->getBillingMock($billingData); $this->paymentDOMock->expects(static::once())->method('getOrder')->willReturn($this->orderMock); $this->orderMock->expects(static::once())->method('getBillingAddress')->willReturn($billingMock); $buildSubject = ['payment' => $this->paymentDOMock]; $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDOMock); self::assertEquals($expectedResult, $this->builder->build($buildSubject)); }
/** * Run test for handle method */ public function testHandle() { $paymentData = $this->getPaymentDataObjectMock(); $transaction = $this->getBraintreeTransactionMock(); $response = ['object' => $transaction]; $handlingSubject = ['payment' => $paymentData]; $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($handlingSubject)->willReturn($paymentData); $this->subjectReaderMock->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction); $this->riskDataHandler->handle($handlingSubject, $response); }
/** * @inheritdoc */ public function build(array $buildSubject) { $result = []; $paymentDO = $this->subjectReader->readPayment($buildSubject); $amount = $this->formatPrice($this->subjectReader->readAmount($buildSubject)); if ($this->is3DSecureEnabled($paymentDO->getOrder(), $amount)) { $result['options'][Config::CODE_3DSECURE] = ['required' => true]; } return $result; }
/** * @inheritdoc */ public function build(array $buildSubject) { $paymentDO = $this->subjectReader->readPayment($buildSubject); $payment = $paymentDO->getPayment(); $transactionId = $payment->getCcTransId(); if (!$transactionId) { throw new LocalizedException(__('No authorization transaction to proceed capture.')); } return [self::TRANSACTION_ID => $transactionId, PaymentDataBuilder::AMOUNT => $this->formatPrice($this->subjectReader->readAmount($buildSubject))]; }
/** * @inheritdoc */ public function handle(array $handlingSubject, array $response) { $paymentDO = $this->subjectReader->readPayment($handlingSubject); /** @var \Braintree\Transaction $transaction */ $transaction = $this->subjectReader->readTransaction($response); /** @var OrderPaymentInterface $payment */ $payment = $paymentDO->getPayment(); $payPal = $this->subjectReader->readPayPal($transaction); $payment->setAdditionalInformation(self::PAYMENT_ID, $payPal[self::PAYMENT_ID]); $payment->setAdditionalInformation(self::PAYER_EMAIL, $payPal[self::PAYER_EMAIL]); }
/** * @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); } }
/** * @covers \Magento\Braintree\Gateway\Request\CaptureDataBuilder::build */ public function testBuild() { $transactionId = 'b3b99d'; $amount = 10.0; $expected = ['transaction_id' => $transactionId, 'amount' => $amount]; $buildSubject = ['payment' => $this->paymentDO, 'amount' => $amount]; $this->payment->expects(static::once())->method('getCcTransId')->willReturn($transactionId); $this->paymentDO->expects(static::once())->method('getPayment')->willReturn($this->payment); $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); $this->subjectReaderMock->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn($amount); static::assertEquals($expected, $this->builder->build($buildSubject)); }
/** * @covers \Magento\Braintree\Gateway\Response\PayPalDetailsHandler::handle */ public function testHandle() { $paymentData = $this->getPaymentDataObjectMock(); $transaction = $this->getBraintreeTransaction(); $subject = ['payment' => $paymentData]; $response = ['object' => $transaction]; $this->subjectReader->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->subjectReader->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction); $this->subjectReader->expects(static::once())->method('readPayPal')->with($transaction)->willReturn($transaction->paypal); $this->payment->expects(static::exactly(2))->method('setAdditionalInformation'); $this->payPalHandler->handle($subject, $response); }
/** * @covers \Magento\Braintree\Gateway\Response\ThreeDSecureDetailsHandler::handle */ public function testHandle() { $paymentData = $this->getPaymentDataObjectMock(); $transaction = $this->getBraintreeTransaction(); $subject = ['payment' => $paymentData]; $response = ['object' => $transaction]; $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->subjectReaderMock->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction); $this->payment->expects(static::at(1))->method('setAdditionalInformation')->with('liabilityShifted', 'Yes'); $this->payment->expects(static::at(2))->method('setAdditionalInformation')->with('liabilityShiftPossible', 'Yes'); $this->handler->handle($subject, $response); }
/** * @param bool $verify * @param float $thresholdAmount * @param string $countryId * @param array $countries * @param array $expected * @covers \Magento\Braintree\Gateway\Request\ThreeDSecureDataBuilder::build * @dataProvider buildDataProvider */ public function testBuild($verify, $thresholdAmount, $countryId, array $countries, array $expected) { $buildSubject = ['payment' => $this->paymentDO, 'amount' => 25]; $this->configMock->expects(static::once())->method('isVerify3DSecure')->willReturn($verify); $this->configMock->expects(static::any())->method('getThresholdAmount')->willReturn($thresholdAmount); $this->configMock->expects(static::any())->method('get3DSecureSpecificCountries')->willReturn($countries); $this->billingAddress->expects(static::any())->method('getCountryId')->willReturn($countryId); $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); $this->subjectReaderMock->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn(25); $result = $this->builder->build($buildSubject); static::assertEquals($expected, $result); }
/** * @inheritdoc */ public function build(array $buildSubject) { $paymentDO = $this->subjectReader->readPayment($buildSubject); $payment = $paymentDO->getPayment(); $order = $paymentDO->getOrder(); $result = [self::AMOUNT => $this->formatPrice($this->subjectReader->readAmount($buildSubject)), self::PAYMENT_METHOD_NONCE => $payment->getAdditionalInformation(DataAssignObserver::PAYMENT_METHOD_NONCE), self::ORDER_ID => $order->getOrderIncrementId()]; $merchantAccountId = $this->config->getValue(Config::KEY_MERCHANT_ACCOUNT_ID); if (!empty($merchantAccountId)) { $result[self::MERCHANT_ACCOUNT_ID] = $merchantAccountId; } return $result; }
public function testValidateSuccess() { $obj = new \stdClass(); $obj->success = true; $obj->paymentMethodNonce = new \stdClass(); $obj->paymentMethodNonce->nonce = 'fj2hd9239kd1kq9'; $subject = ['response' => ['object' => $obj]]; $this->subjectReader->expects(static::once())->method('readResponseObject')->willReturn($obj); $result = $this->getMock(ResultInterface::class); $this->resultInterfaceFactory->expects(self::once())->method('create')->with(['isValid' => true, 'failsDescription' => []])->willReturn($result); $actual = $this->validator->validate($subject); static::assertEquals($result, $actual); }
/** * Handles response * * @param array $handlingSubject * @param array $response * @return void */ public function handle(array $handlingSubject, array $response) { $paymentDO = $this->subjectReader->readPayment($handlingSubject); /** @var \Braintree\Transaction $transaction */ $transaction = $this->subjectReader->readTransaction($response); if (!isset($transaction->riskData)) { return; } $payment = $paymentDO->getPayment(); ContextHelper::assertOrderPayment($payment); $payment->setAdditionalInformation(self::RISK_DATA_ID, $transaction->riskData->id); $payment->setAdditionalInformation(self::RISK_DATA_DECISION, $transaction->riskData->decision); }
public function testBuild() { $additionalData = [[DataAssignObserver::PAYMENT_METHOD_NONCE, self::PAYMENT_METHOD_NONCE]]; $expectedResult = [PaymentDataBuilder::AMOUNT => 10.0, PaymentDataBuilder::PAYMENT_METHOD_NONCE => self::PAYMENT_METHOD_NONCE, PaymentDataBuilder::ORDER_ID => '000000101', PaymentDataBuilder::MERCHANT_ACCOUNT_ID => self::MERCHANT_ACCOUNT_ID]; $buildSubject = ['payment' => $this->paymentDO, 'amount' => 10.0]; $this->paymentMock->expects(static::exactly(count($additionalData)))->method('getAdditionalInformation')->willReturnMap($additionalData); $this->configMock->expects(static::once())->method('getValue')->with(Config::KEY_MERCHANT_ACCOUNT_ID)->willReturn(self::MERCHANT_ACCOUNT_ID); $this->paymentDO->expects(static::once())->method('getPayment')->willReturn($this->paymentMock); $this->paymentDO->expects(static::once())->method('getOrder')->willReturn($this->orderMock); $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); $this->subjectReaderMock->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn(10.0); $this->orderMock->expects(static::once())->method('getOrderIncrementId')->willReturn('000000101'); static::assertEquals($expectedResult, $this->builder->build($buildSubject)); }
/** * Handles response * * @param array $handlingSubject * @param array $response * @return void */ public function handle(array $handlingSubject, array $response) { $paymentDO = $this->subjectReader->readPayment($handlingSubject); if ($paymentDO->getPayment() instanceof Payment) { /** @var \Braintree\Transaction $transaction */ $transaction = $this->subjectReader->readTransaction($response); /** @var Payment $orderPayment */ $orderPayment = $paymentDO->getPayment(); $this->setTransactionId($orderPayment, $transaction); $orderPayment->setIsTransactionClosed($this->shouldCloseTransaction()); $closed = $this->shouldCloseParentTransaction($orderPayment); $orderPayment->setShouldCloseParentTransaction($closed); } }
/** * @inheritdoc */ public function build(array $buildSubject) { $result = []; if (!$this->config->hasFraudProtection()) { return $result; } $paymentDO = $this->subjectReader->readPayment($buildSubject); $payment = $paymentDO->getPayment(); $data = $payment->getAdditionalInformation(); if (isset($data[DataAssignObserver::DEVICE_DATA])) { $result[self::DEVICE_DATA] = $data[DataAssignObserver::DEVICE_DATA]; } return $result; }
/** * @inheritdoc * @throws \Exception */ public function execute(array $commandSubject) { $publicHash = $this->subjectReader->readPublicHash($commandSubject); $customerId = $this->subjectReader->readCustomerId($commandSubject); $paymentToken = $this->tokenManagement->getByPublicHash($publicHash, $customerId); if (!$paymentToken) { throw new Exception('No available payment tokens'); } $data = $this->adapter->createNonce($paymentToken->getGatewayToken()); $result = $this->responseValidator->validate(['response' => ['object' => $data]]); if (!$result->isValid()) { throw new Exception(__(implode("\n", $result->getFailsDescription()))); } return $this->resultFactory->create(['array' => ['paymentMethodNonce' => $data->paymentMethodNonce->nonce]]); }
/** * @inheritdoc */ public function validate(array $validationSubject) { /** @var Successful|Error $response */ $response = $this->subjectReader->readResponseObject($validationSubject); $isValid = true; $errorMessages = []; foreach ($this->getResponseValidators() as $validator) { $validationResult = $validator($response); if (!$validationResult[0]) { $isValid = $validationResult[0]; $errorMessages = array_merge($errorMessages, $validationResult[1]); } } return $this->createResult($isValid, $errorMessages); }
/** * @inheritdoc */ public function build(array $buildSubject) { $paymentDO = $this->subjectReader->readPayment($buildSubject); $order = $paymentDO->getOrder(); $result = []; $billingAddress = $order->getBillingAddress(); if ($billingAddress) { $result[self::BILLING_ADDRESS] = [self::FIRST_NAME => $billingAddress->getFirstname(), self::LAST_NAME => $billingAddress->getLastname(), self::COMPANY => $billingAddress->getCompany(), self::STREET_ADDRESS => $billingAddress->getStreetLine1(), self::EXTENDED_ADDRESS => $billingAddress->getStreetLine2(), self::LOCALITY => $billingAddress->getCity(), self::REGION => $billingAddress->getRegionCode(), self::POSTAL_CODE => $billingAddress->getPostcode(), self::COUNTRY_CODE => $billingAddress->getCountryId()]; } $shippingAddress = $order->getShippingAddress(); if ($shippingAddress) { $result[self::SHIPPING_ADDRESS] = [self::FIRST_NAME => $shippingAddress->getFirstname(), self::LAST_NAME => $shippingAddress->getLastname(), self::COMPANY => $shippingAddress->getCompany(), self::STREET_ADDRESS => $shippingAddress->getStreetLine1(), self::EXTENDED_ADDRESS => $shippingAddress->getStreetLine2(), self::LOCALITY => $shippingAddress->getCity(), self::REGION => $shippingAddress->getRegionCode(), self::POSTAL_CODE => $shippingAddress->getPostcode(), self::COUNTRY_CODE => $shippingAddress->getCountryId()]; } return $result; }
/** * @covers \Magento\Braintree\Gateway\Command\GetPaymentNonceCommand::execute */ public function testExecute() { $publicHash = '3wv2m24d2er3'; $customerId = 1; $token = 'jd2vnq'; $nonce = 's1dj23'; $this->subjectReader->expects(static::once())->method('readPublicHash')->willReturn($publicHash); $this->subjectReader->expects(static::once())->method('readCustomerId')->willReturn($customerId); $this->tokenManagement->expects(static::once())->method('getByPublicHash')->with($publicHash, $customerId)->willReturn($this->paymentToken); $this->paymentToken->expects(static::once())->method('getGatewayToken')->willReturn($token); $obj = new \stdClass(); $obj->success = true; $obj->paymentMethodNonce = new \stdClass(); $obj->paymentMethodNonce->nonce = $nonce; $this->adapter->expects(static::once())->method('createNonce')->with($token)->willReturn($obj); $this->responseValidator->expects(static::once())->method('validate')->with(['response' => ['object' => $obj]])->willReturn($this->validationResult); $this->validationResult->expects(static::once())->method('isValid')->willReturn(true); $this->validationResult->expects(static::never())->method('getFailsDescription'); $expected = $this->getMockBuilder(ArrayResult::class)->disableOriginalConstructor()->setMethods(['get'])->getMock(); $expected->expects(static::once())->method('get')->willReturn(['paymentMethodNonce' => $nonce]); $this->resultFactory->expects(static::once())->method('create')->willReturn($expected); $actual = $this->command->execute(['publicHash' => $publicHash, 'customerId' => $customerId]); static::assertEquals($expected, $actual); static::assertEquals($nonce, $actual->get()['paymentMethodNonce']); }
/** * \Magento\Braintree\Gateway\Request\VaultCaptureDataBuilder::build */ public function testBuild() { $amount = 30.0; $token = '5tfm4c'; $buildSubject = ['payment' => $this->paymentDO, 'amount' => $amount]; $expected = ['amount' => $amount, 'paymentMethodToken' => $token]; $this->subjectReader->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); $this->subjectReader->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn($amount); $paymentExtension = $this->getMockBuilder(OrderPaymentExtension::class)->setMethods(['getVaultPaymentToken'])->disableOriginalConstructor()->getMock(); $paymentToken = $this->getMockBuilder(PaymentToken::class)->disableOriginalConstructor()->getMock(); $paymentExtension->expects(static::once())->method('getVaultPaymentToken')->willReturn($paymentToken); $this->payment->expects(static::once())->method('getExtensionAttributes')->willReturn($paymentExtension); $paymentToken->expects(static::once())->method('getGatewayToken')->willReturn($token); $result = $this->builder->build($buildSubject); static::assertEquals($expected, $result); }
/** * @inheritdoc */ public function handle(array $handlingSubject, array $response) { $paymentDO = $this->subjectReader->readPayment($handlingSubject); $transaction = $this->subjectReader->readTransaction($response); /** * @TODO after changes in sales module should be refactored for new interfaces */ $payment = $paymentDO->getPayment(); ContextHelper::assertOrderPayment($payment); $creditCard = $transaction->creditCard; $payment->setCcLast4($creditCard[self::CARD_LAST4]); $payment->setCcExpMonth($creditCard[self::CARD_EXP_MONTH]); $payment->setCcExpYear($creditCard[self::CARD_EXP_YEAR]); $payment->setCcType($this->getCreditCardType($creditCard[self::CARD_TYPE])); // set card details to additional info $payment->setAdditionalInformation(self::CARD_NUMBER, 'xxxx-' . $creditCard[self::CARD_LAST4]); $payment->setAdditionalInformation(OrderPaymentInterface::CC_TYPE, $creditCard[self::CARD_TYPE]); }
/** * @inheritdoc */ public function handle(array $handlingSubject, array $response) { $paymentDO = $this->subjectReader->readPayment($handlingSubject); /** @var \Braintree\Transaction $transaction */ $transaction = $this->subjectReader->readTransaction($response); /** @var OrderPaymentInterface $payment */ $payment = $paymentDO->getPayment(); $payment->setCcTransId($transaction->id); $payment->setLastTransId($transaction->id); //remove previously set payment nonce $payment->unsAdditionalInformation(DataAssignObserver::PAYMENT_METHOD_NONCE); foreach ($this->additionalInformationMapping as $item) { if (!isset($transaction->{$item})) { continue; } $payment->setAdditionalInformation($item, $transaction->{$item}); } }
/** * Builds ENV request * * @param array $buildSubject * @return array */ public function build(array $buildSubject) { $paymentDO = $this->subjectReader->readPayment($buildSubject); /** @var Payment $payment */ $payment = $paymentDO->getPayment(); $amount = null; try { $amount = $this->formatPrice($this->subjectReader->readAmount($buildSubject)); } catch (\InvalidArgumentException $e) { // pass } /* * we should remember that Payment sets Capture txn id of current Invoice into ParentTransactionId Field * We should also support previous implementations of Magento Braintree - * and cut off '-capture' postfix from transaction ID to support backward compatibility */ $txnId = str_replace('-' . TransactionInterface::TYPE_CAPTURE, '', $payment->getParentTransactionId()); return ['transaction_id' => $txnId, PaymentDataBuilder::AMOUNT => $amount]; }
/** * @inheritdoc */ public function execute(array $commandSubject) { /** @var \Magento\Payment\Gateway\Data\PaymentDataObjectInterface $paymentDO */ $paymentDO = $this->subjectReader->readPayment($commandSubject); /** @var \Magento\Sales\Api\Data\OrderPaymentInterface $paymentInfo */ $paymentInfo = $paymentDO->getPayment(); ContextHelper::assertOrderPayment($paymentInfo); $command = $this->getCommand($paymentInfo); $this->commandPool->get($command)->execute($commandSubject); }