/** * @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 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']); }
/** * {@inheritdoc} */ public function execute($request) { /** @var $request ObtainCreditCard */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } if ($this->request->isMethod('POST')) { $creditCard = new CreditCard(); $creditCard->setHolder($this->request->get('card_holder')); $creditCard->setNumber($this->request->get('card_number')); $creditCard->setSecurityCode($this->request->get('card_cvv')); $creditCard->setExpireAt(new DateTime($this->request->get('card_expire_at'))); $request->set($creditCard); return; } $form = $this->viewFactory->make($this->templateName, ['model' => $request->getModel(), 'firstModel' => $request->getFirstModel(), 'actionUrl' => $request->getToken() ? $request->getToken()->getTargetUrl() : null]); throw new HttpResponse(new Response($form->render(), 200, ['Cache-Control' => 'no-store, no-cache, max-age=0, post-check=0, pre-check=0', 'X-Status-Code' => 200, 'Pragma' => 'no-cache'])); /* $content = $this->viewFactory->make($this->templateName, [ 'model' => $request->getModel(), 'firstModel' => $request->getFirstModel(), 'form' => $form->render(), 'actionUrl' => $request->getToken() ? $request->getToken()->getTargetUrl() : null, ]); $this->gateway->execute($renderTemplate); throw new HttpResponse(new Response($renderTemplate->getResult(), 200, [ 'Cache-Control' => 'no-store, no-cache, max-age=0, post-check=0, pre-check=0', 'X-Status-Code' => 200, 'Pragma' => 'no-cache', ])); */ }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request ObtainCreditCard */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } if (\Request::isMethod('POST')) { $creditCard = new CreditCard(); $creditCard->setHolder(\Input::get('card_holder')); $creditCard->setNumber(\Input::get('card_number')); $creditCard->setSecurityCode(\Input::get('card_cvv')); $creditCard->setExpireAt(new \DateTime(\Input::get('card_expire_at'))); $request->set($creditCard); return; } $content = <<<HTML <!DOCTYPE html> <html> <body> <form method="POST"> <p> <label>Holder: </label> <input name="card_holder" value="" /> </p> <p> <label>Number: </label> <input name="card_number" value="" /> </p> <p> <label>Cvv: </label> <input name="card_cvv" value="" /> </p> <p> <label>Expire at: </label> <input name="card_expire_at" value="" placeholder="yyyy-mm-dd"/> </p> <input type="submit" value="Submit" /> </form> </body> </html> HTML; throw new HttpResponse(new Response($content, 200, array('Cache-Control' => 'no-store, no-cache, max-age=0, post-check=0, pre-check=0', 'Pragma' => 'no-cache'))); }
public function execute($request) { /** @var $request ObtainCreditCard */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } if (\Session::has('cardnum')) { $creditCard = new CreditCard(); $creditCard->setHolder(\Session::get('bname')); $creditCard->setNumber(\Session::get('cardnum')); $creditCard->setSecurityCode(\Session::get('ccv')); $creditCard->setExpireAt(new \DateTime(\Session::get('expDate'))); $request->set($creditCard); return; } return \Redirect::route("home"); }
/** * @test */ public function shouldPassFirstAndCurrentModelsWithObtainCreditCardSubRequest() { $firstModel = new \stdClass(); $currentModel = new \ArrayObject(array('AMOUNT' => 10, 'CLIENTUSERAGENT' => 'anAgent', 'CLIENTIP' => '127.0.0.1')); $apiMock = $this->createApiMock(); $apiMock->expects($this->once())->method('payment')->will($this->returnValue(array('FOO' => 'FOOVAL', 'BAR' => 'BARVAL'))); $gatewayMock = $this->createGatewayMock(); $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\ObtainCreditCard'))->will($this->returnCallback(function (ObtainCreditCard $request) use($firstModel, $currentModel) { $this->assertSame($firstModel, $request->getFirstModel()); $this->assertSame($currentModel, $request->getModel()); $card = new CreditCard(); $card->setExpireAt(new \DateTime('2014-10-01')); $request->set($card); })); $action = new CaptureAction(); $action->setApi($apiMock); $action->setGateway($gatewayMock); $capture = new Capture($firstModel); $capture->setModel($currentModel); $action->execute($capture); }
/** * @test */ public function shouldCaptureWithObtainedCreditCard() { $gatewayMock = $this->createGatewayMock(); $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\ObtainCreditCard'))->will($this->returnCallback(function (ObtainCreditCard $request) { $card = new CreditCard(); $card->setNumber('1234567812345678'); $card->setExpireAt(new \DateTime('2014-10-01')); $card->setHolder('John Doe'); $card->setSecurityCode('123'); $request->set($card); })); $result = array('FOO' => 'FOOVAL', 'BAR' => 'BARVAL'); $apiMock = $this->createApiMock(); $apiMock->expects($this->once())->method('doSale')->will($this->returnValue($result)); $action = new CaptureAction(); $action->setApi($apiMock); $action->setGateway($gatewayMock); $request = new Capture(array('AMOUNT' => 10)); //guard $this->assertTrue($action->supports($request)); $action->execute($request); $model = iterator_to_array($request->getModel()); $this->assertArrayHasKey('AMOUNT', $model); $this->assertEquals(10, $model['AMOUNT']); $this->assertArrayHasKey('FOO', $model); $this->assertEquals('FOOVAL', $model['FOO']); }
/** * @test */ public function shouldCaptureWithObtainedCreditCard() { $api = $this->createAuthorizeNetAIMMock(); $api->expects($this->once())->method('authorizeAndCapture')->will($this->returnValue($this->createAuthorizeNetAIMResponseMock())); $gatewayMock = $this->createGatewayMock(); $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf('Payum\\Core\\Request\\ObtainCreditCard'))->will($this->returnCallback(function (ObtainCreditCard $request) { $card = new CreditCard(); $card->setNumber('1234567812345678'); $card->setExpireAt(new \DateTime('2014-10-01')); $request->set($card); })); $action = new CaptureAction(); $action->setApi($api); $action->setGateway($gatewayMock); $action->execute(new Capture(array('amount' => 10))); }
/** * @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']); }
/** * @test */ public function shouldSecureOnlyChangedFields() { $card = new CreditCard(); $card->setNumber('1234'); $card->secure(); //guard $this->assertNull($this->readAttribute($card, 'number')); $this->assertInstanceOf('Payum\\Core\\Security\\SensitiveValue', $this->readAttribute($card, 'securedNumber')); $card->setNumber('John Doe'); $card->secure(); $this->assertNull($this->readAttribute($card, 'holder')); $this->assertInstanceOf('Payum\\Core\\Security\\SensitiveValue', $this->readAttribute($card, 'securedHolder')); $this->assertNull($this->readAttribute($card, 'number')); $this->assertInstanceOf('Payum\\Core\\Security\\SensitiveValue', $this->readAttribute($card, 'securedNumber')); }
/** * @test */ public function shouldCaptureWithObtainedCreditCard() { $paymentMock = $this->createPaymentMock(); $paymentMock ->expects($this->once()) ->method('execute') ->with($this->isInstanceOf('Payum\Core\Request\ObtainCreditCard')) ->will($this->returnCallback(function (ObtainCreditCard $request) { $card = new CreditCard(); $card->setNumber('1234567812345678'); $card->setExpireAt(new \DateTime('2014-10-01')); $card->setHolder('John Doe'); $card->setSecurityCode('123'); $request->set($card); })) ; $apiResponse = new JsonResponse(); $apiResponse->setContent(json_encode(array( 'FOO' => 'FOOVAL', 'BAR' => 'BARVAL', ))); $apiMock = $this->createApiMock(); $apiMock ->expects($this->once()) ->method('payment') ->will($this->returnValue($apiResponse)) ; $action = new CaptureAction(); $action->setApi($apiMock); $action->setPayment($paymentMock); $request = new Capture(array( 'AMOUNT' => 10, 'CLIENTUSERAGENT' => 'anAgent', 'CLIENTIP' => '127.0.0.1', )); //guard $this->assertTrue($action->supports($request)); $action->execute($request); $model = iterator_to_array($request->getModel()); $this->assertArrayHasKey('AMOUNT', $model); $this->assertEquals(10, $model['AMOUNT']); $this->assertArrayHasKey('FOO', $model); $this->assertEquals('FOOVAL', $model['FOO']); }
/** * @test */ public function shouldStoreExpireAtAsSensitiveValue() { $card = new CreditCard(); $expected = new \DateTime(); $card->setExpireAt($expected); $value = $this->readAttribute($card, 'securedExpireAt'); $this->assertInstanceOf(SensitiveValue::class, $value); $this->assertSame($expected, $value->peek()); }
/** * @test */ public function shouldObtainCreditCardAndPopulateCardReferenceFieldIfNotSet() { $firstModel = new \stdClass(); $model = new \ArrayObject([]); $responseMock = $this->getMock(OmnipayAbstractResponse::class, [], [], '', false); $responseMock->expects($this->once())->method('getData')->willReturn([]); $requestMock = $this->getMock(OmnipayRequestInterface::class); $requestMock->expects($this->once())->method('send')->willReturn($responseMock); $omnipayGateway = $this->getMock(CreditCardGateway::class, [], [], '', false); $omnipayGateway->expects($this->once())->method('purchase')->with(['cardReference' => 'theCardToken', 'clientIp' => ''])->willReturn($requestMock); $gateway = $this->createGatewayMock(); $gateway->expects($this->at(0))->method('execute')->with($this->isInstanceOf(ObtainCreditCard::class))->willReturnCallback(function (ObtainCreditCard $request) use($firstModel, $model) { $this->assertSame($firstModel, $request->getFirstModel()); $this->assertSame($model, $request->getModel()); $card = new CreditCard(); $card->setToken('theCardToken'); $request->set($card); }); $action = new CaptureAction(); $action->setApi($omnipayGateway); $action->setGateway($gateway); $capture = new Capture($firstModel); $capture->setModel($model); $action->execute($capture); $details = iterator_to_array($model); $this->assertArrayNotHasKey('card', $details); $this->assertArrayHasKey('cardReference', $details); $this->assertEquals('theCardToken', $details['cardReference']); }