/** * @test */ public function shouldCorrectlyConvertPaymentToArray() { $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'; }); $payment = new Payment(); $payment->setNumber('theNumber'); $payment->setCurrencyCode('USD'); $payment->setTotalAmount(123); $payment->setDescription('the description'); $payment->setClientId('theClientId'); $payment->setClientEmail('theClientEmail'); $action = new ConvertPaymentAction(); $action->setGateway($gatewayMock); $action->execute($convert = new Convert($payment, 'array')); $result = $convert->getResult(); $this->assertInternalType('array', $result); $this->assertNotEmpty($result); $this->assertArrayHasKey('amount', $result); $this->assertEquals(1.23, $result['amount']); $this->assertArrayHasKey('invoice_num', $result); $this->assertEquals('theNumber', $result['invoice_num']); $this->assertArrayHasKey('description', $result); $this->assertEquals('the description', $result['description']); $this->assertArrayHasKey('cust_id', $result); $this->assertEquals('theClientId', $result['cust_id']); $this->assertArrayHasKey('email', $result); $this->assertEquals('theClientEmail', $result['email']); }
/** * {@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); } }
/** * {@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 shouldCorrectlyConvertOrderToDetailsAndSetItBack() { $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->setNumber('theNumber'); $order->setCurrencyCode('USD'); $order->setTotalAmount(123); $order->setDescription('the description'); $order->setClientId('theClientId'); $order->setClientEmail('theClientEmail'); $action = new ConvertPaymentAction(); $action->setGateway($gatewayMock); $action->execute($convert = new Convert($order, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('AMT', $details); $this->assertEquals(1.23, $details['AMT']); $this->assertArrayHasKey('CURRENCY', $details); $this->assertEquals('USD', $details['CURRENCY']); }
/** * @test */ public function shouldCorrectlyConvertOrderToDetailsAndSetItBack() { $order = new Payment(); $order->setNumber('theNumber'); $order->setCurrencyCode('USD'); $order->setTotalAmount(123); $order->setDescription('the description'); $order->setClientId('theClientId'); $order->setClientEmail('theClientEmail'); $action = new ConvertPaymentAction(); $action->execute($convert = new Convert($order, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('price', $details); $this->assertEquals(123, $details['price']); $this->assertArrayHasKey('currency', $details); $this->assertEquals('USD', $details['currency']); $this->assertArrayHasKey('orderId', $details); $this->assertEquals('theNumber', $details['orderId']); $this->assertArrayHasKey('description', $details); $this->assertEquals('the description', $details['description']); // should not work if we pass anything. Not sure what it should be $this->assertArrayHasKey('clientIdentifier', $details); $this->assertEquals('', $details['clientIdentifier']); $this->assertArrayHasKey('autoPay', $details); $this->assertEquals(false, $details['autoPay']); }
/** * @test */ public function shouldCorrectlyConvertPaymentWithCreditCardToDetailsArray() { $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'; }); $creditCard = new CreditCard(); $creditCard->setNumber('4444333322221111'); $creditCard->setHolder('John Doe'); $creditCard->setSecurityCode('322'); $creditCard->setExpireAt(new \DateTime('2015-11-12')); $payment = new Payment(); $payment->setNumber('theNumber'); $payment->setCurrencyCode('USD'); $payment->setTotalAmount(123); $payment->setDescription('the description'); $payment->setClientId('theClientId'); $payment->setClientEmail('theClientEmail'); $payment->setCreditCard($creditCard); $action = new ConvertPaymentAction(); $action->setGateway($gatewayMock); $action->execute($convert = new Convert($payment, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('card', $details); $this->assertInstanceOf(SensitiveValue::class, $details['card']); $this->assertEquals(array('number' => '4444333322221111', 'cvv' => '322', 'expiryMonth' => '11', 'expiryYear' => '15', 'firstName' => 'John Doe', 'lastName' => ''), $details['card']->peek()); }
/** * @test */ public function shouldCorrectlyConvertOrderToDetailsAndSetItBack() { $order = new Payment(); $order->setNumber('theNumber'); $order->setCurrencyCode('USD'); $order->setTotalAmount(123); $order->setDescription('the description'); $order->setClientId('theClientId'); $order->setClientEmail('theClientEmail'); $action = new ConvertPaymentAction(); $action->execute($convert = new Convert($order, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('amount', $details); $this->assertEquals(123, $details['amount']); $this->assertArrayHasKey('currency', $details); $this->assertEquals('USD', $details['currency']); $this->assertArrayHasKey('number', $details); $this->assertEquals('theNumber', $details['number']); $this->assertArrayHasKey('description', $details); $this->assertEquals('the description', $details['description']); $this->assertArrayHasKey('client_id', $details); $this->assertEquals('theClientId', $details['client_id']); $this->assertArrayHasKey('client_email', $details); $this->assertEquals('theClientEmail', $details['client_email']); $this->assertArrayHasKey(Constants::FIELD_PAID, $details); $this->assertEquals(true, $details[Constants::FIELD_PAID]); }
/** * @test */ public function shouldDoNothingIfCurrencyNotSEK() { $payment = new Payment(); $payment->setNumber('theNumber'); $payment->setCurrencyCode('USD'); $payment->setTotalAmount(123); $payment->setDescription('the description'); $payment->setClientId('theClientId'); $payment->setClientEmail('theClientEmail'); $action = new ConvertPaymentAction(); $action->execute($convert = new Convert($payment, 'array')); $details = $convert->getResult(); $this->assertEquals([], $details); }
/** * @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 shouldCorrectlyConvertOrderToDetailsAndSetItBack() { $payment = new Payment(); $payment->setNumber('theNumber'); $payment->setCurrencyCode('USD'); $payment->setTotalAmount(123); $payment->setDescription('the description'); $payment->setClientId('theClientId'); $payment->setClientEmail('theClientEmail'); $action = new ConvertPaymentAction(); $action->execute($convert = new Convert($payment, 'array')); $details = $convert->getResult(); $this->assertNotEmpty($details); $this->assertArrayHasKey('AMOUNT', $details); $this->assertEquals(123, $details['AMOUNT']); $this->assertArrayHasKey('ORDERID', $details); $this->assertEquals('theNumber', $details['ORDERID']); $this->assertArrayHasKey('DESCRIPTION', $details); $this->assertEquals('the description', $details['DESCRIPTION']); $this->assertArrayHasKey('CLIENTIDENT', $details); $this->assertEquals('theClientId', $details['CLIENTIDENT']); $this->assertArrayHasKey('CLIENTEMAIL', $details); $this->assertEquals('theClientEmail', $details['CLIENTEMAIL']); }
/** * @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']); }