/** * @test */ public function shouldAllowEraseValue() { $expectedValue = 'cardNumber'; $sensitiveValue = new SensitiveValue($expectedValue); //guard $this->assertEquals($expectedValue, $sensitiveValue->get()); $sensitiveValue->erase(); $this->assertNull($sensitiveValue->get()); $this->assertAttributeEquals(null, 'value', $sensitiveValue); }
/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $details = ArrayObject::ensureArrayObject($request->getModel()); if ($details['_status']) { return; } if (false == $details['_completeCaptureRequired']) { if (false == $details->validateNotEmpty(array('card'), false) && false == $details->validateNotEmpty(array('cardReference'), false)) { try { $obtainCreditCard = new ObtainCreditCard($request->getFirstModel(), $request->getModel()); $this->gateway->execute($obtainCreditCard); $card = $obtainCreditCard->obtain(); if ($card->getToken()) { $details['cardReference'] = $card->getToken(); } else { $details['card'] = SensitiveValue::ensureSensitive(array('number' => $card->getNumber(), 'cvv' => $card->getSecurityCode(), 'expiryMonth' => $card->getExpireAt()->format('m'), 'expiryYear' => $card->getExpireAt()->format('y'), 'firstName' => $card->getHolder(), 'lastName' => '')); } } catch (RequestNotSupportedException $e) { throw new LogicException('Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.'); } } } parent::execute($request); }
/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $model = ArrayObject::ensureArrayObject($request->getModel()); if (null != $model['response_code']) { return; } if (false == $model->validateNotEmpty(array('card_num', 'exp_date'), false)) { try { $obtainCreditCard = new ObtainCreditCard($request->getToken()); $obtainCreditCard->setModel($request->getFirstModel()); $obtainCreditCard->setModel($request->getModel()); $this->gateway->execute($obtainCreditCard); $card = $obtainCreditCard->obtain(); $model['exp_date'] = SensitiveValue::ensureSensitive($card->getExpireAt()->format('m/y')); $model['card_num'] = SensitiveValue::ensureSensitive($card->getNumber()); } catch (RequestNotSupportedException $e) { throw new LogicException('Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.'); } } $api = clone $this->api; $api->ignore_not_x_fields = true; $api->setFields(array_filter($model->toUnsafeArray())); $response = $api->authorizeAndCapture(); $model->replace(get_object_vars($response)); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request Capture */ RequestNotSupportedException::assertSupports($this, $request); $model = new ArrayObject($request->getModel()); if (is_numeric($model['RESULT'])) { return; } $cardFields = array('ACCT', 'CVV2', 'EXPDATE'); if (false == $model->validateNotEmpty($cardFields, false)) { try { $obtainCreditCard = new ObtainCreditCard($request->getToken()); $obtainCreditCard->setModel($request->getFirstModel()); $obtainCreditCard->setModel($request->getModel()); $this->gateway->execute($obtainCreditCard); $card = $obtainCreditCard->obtain(); $model['EXPDATE'] = SensitiveValue::ensureSensitive($card->getExpireAt()->format('my')); $model['ACCT'] = SensitiveValue::ensureSensitive($card->getNumber()); $model['CVV2'] = SensitiveValue::ensureSensitive($card->getSecurityCode()); } catch (RequestNotSupportedException $e) { throw new LogicException('Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.'); } } $model->replace($this->api->doSale($model->toUnsafeArray())); }
/** * {@inheritDoc} */ public function setExpireAt($date = null) { $date = SensitiveValue::ensureSensitive($date); if (false == (null === $date->peek() || $date->peek() instanceof \DateTime)) { throw new InvalidArgumentException('The date argument must be either instance of DateTime or null'); } $this->securedExpireAt = $date; // BC $this->expireAt = $this->securedExpireAt->peek(); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request CreateTokenForCreditCard */ RequestNotSupportedException::assertSupports($this, $request); /** @var CreditCardInterface $card */ $card = $request->getModel(); $token = ArrayObject::ensureArrayObject($request->getToken()); $token['object'] = 'card'; $token['number'] = SensitiveValue::ensureSensitive($card->getNumber()); $token['exp_month'] = SensitiveValue::ensureSensitive($card->getExpireAt()->format('m')); $token['exp_year'] = SensitiveValue::ensureSensitive($card->getExpireAt()->format('Y')); if ($card->getSecurityCode()) { $token['cvc'] = SensitiveValue::ensureSensitive($card->getSecurityCode()); } $this->gateway->execute(new CreateToken($token)); $request->setToken($token->toUnsafeArray()); }
/** * {@inheritDoc} * * @param Convert $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); /** @var PaymentInterface $payment */ $payment = $request->getSource(); $this->gateway->execute($currency = new GetCurrency($payment->getCurrencyCode())); $divisor = pow(10, $currency->exp); $details = $payment->getDetails(); $details['amount'] = (double) $payment->getTotalAmount() / $divisor; $details['currency'] = $payment->getCurrencyCode(); $details['description'] = $payment->getDescription(); if ($payment->getCreditCard()) { $card = $payment->getCreditCard(); $details['card'] = SensitiveValue::ensureSensitive(array('number' => $card->getNumber(), 'cvv' => $card->getSecurityCode(), 'expiryMonth' => $card->getExpireAt()->format('m'), 'expiryYear' => $card->getExpireAt()->format('y'), 'firstName' => $card->getHolder(), 'lastName' => '')); } $request->setResult((array) $details); }
/** * {@inheritDoc} * * @param Convert $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); /** @var PaymentInterface $payment */ $payment = $request->getSource(); $details = ArrayObject::ensureArrayObject($payment->getDetails()); $details["amount"] = $payment->getTotalAmount(); $details["currency"] = $payment->getCurrencyCode(); $details["description"] = $payment->getDescription(); if ($card = $payment->getCreditCard()) { if ($card->getToken()) { $details["customer"] = $card->getToken(); } else { $details["card"] = SensitiveValue::ensureSensitive(['number' => $card->getNumber(), 'exp_month' => $card->getExpireAt()->format('m'), 'exp_year' => $card->getExpireAt()->format('Y'), 'cvc' => $card->getSecurityCode()]); } } $request->setResult((array) $details); }
/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { RequestNotSupportedException::assertSupports($this, $request); $model = new ArrayObject($request->getModel()); if (null !== $model['EXECCODE']) { return; } if (false == $model['CLIENTUSERAGENT']) { $this->gateway->execute($httpRequest = new GetHttpRequest()); $model['CLIENTUSERAGENT'] = $httpRequest->userAgent; } if (false == $model['CLIENTIP']) { $this->gateway->execute($httpRequest = new GetHttpRequest()); $model['CLIENTIP'] = $httpRequest->clientIp; } $cardFields = array('CARDCODE', 'CARDCVV', 'CARDVALIDITYDATE', 'CARDFULLNAME'); if (false == $model->validateNotEmpty($cardFields, false) && false == $model['ALIAS']) { try { $obtainCreditCard = new ObtainCreditCard($request->getToken()); $obtainCreditCard->setModel($request->getFirstModel()); $obtainCreditCard->setModel($request->getModel()); $this->gateway->execute($obtainCreditCard); $card = $obtainCreditCard->obtain(); if ($card->getToken()) { $model['ALIAS'] = $card->getToken(); } else { $model['CARDVALIDITYDATE'] = SensitiveValue::ensureSensitive($card->getExpireAt()->format('m-y')); $model['CARDCODE'] = SensitiveValue::ensureSensitive($card->getNumber()); $model['CARDFULLNAME'] = SensitiveValue::ensureSensitive($card->getHolder()); $model['CARDCVV'] = SensitiveValue::ensureSensitive($card->getSecurityCode()); } } catch (RequestNotSupportedException $e) { throw new LogicException('Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.'); } } //instruction must have an alias set (e.g oneclick payment) or credit card info. if (false == ($model['ALIAS'] || $model->validateNotEmpty($cardFields, false))) { throw new LogicException('Either credit card fields or its alias has to be set.'); } $result = $this->api->payment($model->toUnsafeArray()); $model->replace((array) $result); }
/** * {@inheritDoc} */ public function getExpireAt() { return $this->securedExpireAt ? $this->securedExpireAt->peek() : $this->expireAt; }
/** * @test */ public function shouldConvertArrayObjectToPrimitiveArrayMakingSensitiveValueUnsafeAndEraseIt() { $sensitiveValue = new SensitiveValue('theCreditCard'); $arrayObject = new ArrayObject(); $arrayObject['creditCard'] = $sensitiveValue; $arrayObject['email'] = '*****@*****.**'; $primitiveArray = $arrayObject->toUnsafeArray(); $this->assertInternalType('array', $primitiveArray); $this->assertArrayHasKey('creditCard', $primitiveArray); $this->assertEquals('theCreditCard', $primitiveArray['creditCard']); $this->assertArrayHasKey('email', $primitiveArray); $this->assertEquals('*****@*****.**', $primitiveArray['email']); $this->assertNull($sensitiveValue->peek()); }
/** * @test */ public function shouldReturnSameInstanceOfSensitiveValueGivenAsArgumentOnEnsureSensitive() { $foo = new SensitiveValue('foo'); $this->assertSame($foo, SensitiveValue::ensureSensitive($foo)); }