/** * {@inheritdoc} * * @param $request Capture */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); /** @var $payment SyliusPaymentInterface */ $payment = $request->getModel(); /** @var OrderInterface $order */ $order = $payment->getOrder(); $this->gateway->execute($status = new GetStatus($payment)); if ($status->isNew()) { try { $this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken())); $payment->setDetails($convert->getResult()); } catch (RequestNotSupportedException $e) { $totalAmount = $order->getTotal(); $payumPayment = new PayumPayment(); $payumPayment->setNumber($order->getNumber()); $payumPayment->setTotalAmount($totalAmount); $payumPayment->setCurrencyCode($order->getCurrencyCode()); $payumPayment->setClientEmail($order->getCustomer()->getEmail()); $payumPayment->setClientId($order->getCustomer()->getId()); $payumPayment->setDescription(sprintf('Payment contains %d items for a total of %01.2f', $order->getItems()->count(), round($totalAmount / 100, 2))); $payumPayment->setDetails($payment->getDetails()); $this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken())); $payment->setDetails($convert->getResult()); } } $details = ArrayObject::ensureArrayObject($payment->getDetails()); try { $request->setModel($details); $this->gateway->execute($request); } finally { $payment->setDetails((array) $details); } }
/** * @test */ public function shouldCorrectlyConvertCreditCard() { $creditCard = new CreditCard(); $creditCard->setNumber('4111111111111111'); $creditCard->setExpireAt(new \DateTime('2018-05-12')); $creditCard->setSecurityCode(123); $creditCard->setHolder('John Doe'); $order = new Payment(); $order->setCreditCard($creditCard); $action = new ConvertPaymentAction(); $action->execute($convert = new Convert($order, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('card', $details); $this->assertInstanceOf('Payum\\Core\\Security\\SensitiveValue', $details['card']); $card = $details['card']->peek(); $this->assertInternalType('array', $card); $this->assertArrayHasKey('number', $card); $this->assertEquals('4111111111111111', $card['number']); $this->assertArrayHasKey('exp_month', $card); $this->assertEquals('05', $card['exp_month']); $this->assertArrayHasKey('exp_year', $card); $this->assertEquals('2018', $card['exp_year']); $this->assertArrayHasKey('cvc', $card); $this->assertEquals('123', $card['cvc']); }
/** * @test */ public function shouldAllowGetBankAccountPreviouslySet() { $order = new Payment(); $bankAccountMock = $this->getMock(BankAccountInterface::class); $order->setBankAccount($bankAccountMock); $this->assertSame($bankAccountMock, $order->getBankAccount()); }
/** * @test */ public function shouldAllowGetCreditCardPreviouslySet() { $order = new Payment(); $creditCardMock = $this->getMock(CreditCardInterface::class); $order->setCreditCard($creditCardMock); $this->assertSame($creditCardMock, $order->getCreditCard()); }
/** * @test */ public function shouldAllowGetCreditCardPreviouslySet() { $order = new Payment(); $creditCardMock = $this->getMock('Payum\\Core\\Model\\CreditCardInterface'); $order->setCreditCard($creditCardMock); $this->assertSame($creditCardMock, $order->getCreditCard()); }
/** * {@inheritDoc} * * @param $request Authorize */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); /** @var $payment Payment */ $payment = $request->getModel(); $this->gateway->execute($status = new GetHumanStatus($payment)); if ($status->isNew()) { $this->gateway->execute(new ObtainMissingDetailsRequest($payment, $request->getToken())); try { $this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken())); $payment->setDetails($convert->getResult()); } catch (RequestNotSupportedException $e) { $payumPayment = new PayumPayment(); $payumPayment->setNumber($payment->getNumber()); $payumPayment->setTotalAmount($payment->getTotalAmount()); $payumPayment->setCurrencyCode($payment->getCurrencyCode()); $payumPayment->setClientEmail($payment->getPayer()->getEmail()); $payumPayment->setClientId($payment->getPayer()->getId() ?: $payment->getPayer()->getEmail()); $payumPayment->setDescription($payment->getDescription() ?: sprintf('Payment %s', $payment->getNumber())); $payumPayment->setCreditCard($payment->getCreditCard()); $payumPayment->setDetails($payment->getDetails()); $this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken())); $payment->setDetails($convert->getResult()); } } $details = ArrayObject::ensureArrayObject($payment->getDetails()); try { $request->setModel($details); $this->gateway->execute($request); } finally { $payment->setDetails((array) $details); } }
/** * @test */ public function shouldNotOverwriteAlreadySetExtraDetails() { $payment = new Payment(); $payment->setCurrencyCode('USD'); $payment->setTotalAmount(123); $payment->setDescription('the description'); $payment->setDetails(array('foo' => 'fooVal')); $action = new ConvertPaymentAction(); $action->execute($convert = new Convert($payment, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('foo', $details); $this->assertEquals('fooVal', $details['foo']); }
/** * @test */ public function shouldNotOverrideProvidesValue() { $payment = new Payment(); $payment->setNumber('1234'); $payment->setCurrencyCode('USD'); $payment->setTotalAmount(123); $payment->setDescription('the description'); $payment->setClientId('theClientId'); $payment->setClientEmail('theClientEmail'); $payment->setDetails(array('Ds_Merchant_MerchantURL' => 'a_merchant_url', 'Ds_Merchant_TransactionType' => 1, 'Ds_Merchant_ConsumerLanguage' => '002')); $apiMock = $this->createApiMock(); $apiMock->expects($this->once())->method('ensureCorrectOrderNumber')->with($payment->getNumber())->willReturn($payment->getNumber()); $apiMock->expects($this->once())->method('getISO4127')->with($payment->getCurrencyCode())->willReturn(840); $apiMock->expects($this->once())->method('getMerchantCode')->willReturn('a_merchant_code'); $apiMock->expects($this->once())->method('getMerchantTerminalCode')->willReturn('001'); $tokenMock = $this->getMock('Payum\\Core\\Security\\TokenInterface'); $action = new ConvertPaymentAction(); $action->setApi($apiMock); $action->execute(new Convert($payment, 'array', $tokenMock)); $details = $payment->getDetails(); $this->assertNotEmpty($details); $this->assertArrayHasKey('Ds_Merchant_MerchantURL', $details); $this->assertEquals('a_merchant_url', $details['Ds_Merchant_MerchantURL']); $this->assertArrayHasKey('Ds_Merchant_TransactionType', $details); $this->assertEquals(1, $details['Ds_Merchant_TransactionType']); $this->assertArrayHasKey('Ds_Merchant_ConsumerLanguage', $details); $this->assertEquals('002', $details['Ds_Merchant_ConsumerLanguage']); }
/** * @test */ public function shouldNotOverwriteAlreadySetExtraDetails() { $gatewayMock = $this->getMock('Payum\\Core\\GatewayInterface'); $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\GetCurrency'))->willReturnCallback(function (GetCurrency $request) { $request->name = 'US Dollar'; $request->alpha3 = 'USD'; $request->numeric = 123; $request->exp = 2; $request->country = 'US'; }); $order = new Payment(); $order->setCurrencyCode('USD'); $order->setTotalAmount(123); $order->setDescription('the description'); $order->setDetails(array('foo' => 'fooVal')); $action = new ConvertPaymentAction(); $action->setGateway($gatewayMock); $action->execute($convert = new Convert($order, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('foo', $details); $this->assertEquals('fooVal', $details['foo']); }
/** * @test */ public function shouldCorrectlyConvertOrderToDetailsAndSetItBack() { $payment = new Payment(); $payment->setNumber('theNumber'); $payment->setCurrencyCode('EUR'); $payment->setTotalAmount(1000); $payment->setClientId('theClientId'); $payment->setClientEmail('theClientEmail'); $action = new ConvertPaymentAction(); $action->execute($convert = new Convert($payment, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('merchantReference', $details); $this->assertEquals('theNumber', $details['merchantReference']); $this->assertArrayHasKey('paymentAmount', $details); $this->assertEquals(1000, $details['paymentAmount']); $this->assertArrayHasKey('shopperEmail', $details); $this->assertEquals('theClientEmail', $details['shopperEmail']); $this->assertArrayHasKey('currencyCode', $details); $this->assertEquals('EUR', $details['currencyCode']); $this->assertArrayHasKey('shopperReference', $details); $this->assertEquals('theClientId', $details['shopperReference']); }
/** * @test */ public function shouldSetDetailsBackToPaymentEvenIfExceptionThrown() { $expectedDetails = array('foo' => 'fooVal'); $payment = new Payment(); $payment->setDetails($expectedDetails); $gatewayMock = $this->createGatewayMock(); $gatewayMock->expects($this->at(0))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\GetHumanStatus'))->will($this->returnCallback(function (GetHumanStatus $request) { $request->markPending(); })); $gatewayMock->expects($this->at(1))->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\Capture'))->will($this->returnCallback(function (Capture $request) { $details = $request->getModel(); $details['bar'] = 'barVal'; throw new \Exception(); })); $action = new CapturePaymentAction(); $action->setGateway($gatewayMock); $this->setExpectedException('Exception'); $action->execute($capture = new Capture($payment)); $this->assertSame($payment, $capture->getFirstModel()); $this->assertInstanceOf('ArrayAccess', $capture->getModel()); $this->assertEquals(array('foo' => 'fooVal', 'bar' => 'barVal'), $payment->getDetails()); }
/** * @test */ public function shouldCorrectlyConvertCreditCardToken() { $creditCard = new CreditCard(); $creditCard->setToken('theCustomerId'); $order = new Payment(); $order->setCreditCard($creditCard); $action = new ConvertPaymentAction(); $action->execute($convert = new Convert($order, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('customer', $details); $this->assertEquals('theCustomerId', $details['customer']); }
public function setDetails($details) { parent::setDetails($details); }