Beispiel #1
1
 /**
  * {@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 shouldCorrectlyConvertOrderToDetailsAndSetItBack()
 {
     $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'));
     $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($convert = new Convert($payment, 'array', $tokenMock));
     $details = $convert->getResult();
     $this->assertNotEmpty($details);
     $this->assertArrayHasKey('Ds_Merchant_Amount', $details);
     $this->assertEquals(123, $details['Ds_Merchant_Amount']);
     $this->assertArrayHasKey('Ds_Merchant_Order', $details);
     $this->assertEquals('1234', $details['Ds_Merchant_Order']);
     $this->assertArrayHasKey('Ds_Merchant_Currency', $details);
     $this->assertEquals(840, $details['Ds_Merchant_Currency']);
     $this->assertArrayHasKey('Ds_Merchant_MerchantCode', $details);
     $this->assertEquals('a_merchant_code', $details['Ds_Merchant_MerchantCode']);
     $this->assertArrayHasKey('Ds_Merchant_Terminal', $details);
     $this->assertEquals('001', $details['Ds_Merchant_Terminal']);
     $this->assertArrayHasKey('Ds_Merchant_MerchantURL', $details);
     $this->assertEquals('a_merchant_url', $details['Ds_Merchant_MerchantURL']);
 }
 /**
  * {@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);
     }
 }
Beispiel #4
0
 /**
  * @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']);
 }
 function it_supports_only_converting_to_array_from_payment(Convert $fromSomethingElseToSomethingElseRequest, Convert $fromPaymentToArrayRequest, PaymentInterface $payment, PaymentMethodInterface $method)
 {
     $fromPaymentToArrayRequest->getTo()->willReturn('array');
     $fromPaymentToArrayRequest->getSource()->willReturn($payment);
     $fromSomethingElseToSomethingElseRequest->getTo()->willReturn('json');
     $fromSomethingElseToSomethingElseRequest->getSource()->willReturn($method);
     $this->supports($fromPaymentToArrayRequest)->shouldReturn(true);
     $this->supports($fromSomethingElseToSomethingElseRequest)->shouldReturn(false);
 }
 /**
  * @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']);
 }
Beispiel #7
0
 /**
  * {@inheritDoc}
  *
  * @param Payout $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     /** @var $payout PayoutInterface */
     $payout = $request->getModel();
     $this->gateway->execute($status = new GetHumanStatus($payout));
     if ($status->isNew()) {
         $this->gateway->execute($convert = new Convert($payout, 'array', $request->getToken()));
         $payout->setDetails($convert->getResult());
     }
     $details = ArrayObject::ensureArrayObject($payout->getDetails());
     $request->setModel($details);
     try {
         $this->gateway->execute($request);
     } finally {
         $payout->setDetails($details);
     }
 }
 /**
  * @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']);
 }
Beispiel #10
0
 /**
  * @test
  */
 public function shouldNotOverwriteAlreadySetExtraDetails()
 {
     $gatewayMock = $this->getMock(GatewayInterface::class);
     $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf(GetCurrency::class))->willReturnCallback(function (GetCurrency $request) {
         $request->name = 'US Dollar';
         $request->alpha3 = 'USD';
         $request->numeric = 123;
         $request->exp = 2;
         $request->country = 'US';
     });
     $payoutModel = new Payout();
     $payoutModel->setRecipientEmail('theRecipientEmail');
     $payoutModel->setCurrencyCode('USD');
     $payoutModel->setTotalAmount(123);
     $payoutModel->setDescription('the description');
     $payoutModel->setDetails(['foo' => 'fooVal']);
     $action = new ConvertPayoutAction();
     $action->setGateway($gatewayMock);
     $action->execute($convert = new Convert($payoutModel, 'array'));
     $details = $convert->getResult();
     $this->assertNotEmpty($details);
     $this->assertEquals(['CURRENCYCODE' => 'USD', 'L_AMT0' => 1.23, 'L_NOTE0' => 'the description', 'RECEIVERTYPE' => 'EmailAddress', 'L_EMAIL0' => 'theRecipientEmail', 'foo' => 'fooVal'], $details);
 }
 function it_throws_exception_when_source_is_not_a_payment_interface(Convert $request)
 {
     $request->getSource()->willReturn(null);
     $this->shouldThrow(RequestNotSupportedException::class)->during('execute', [$request]);
 }
 /**
  * @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']);
 }
Beispiel #13
0
 /**
  * @test
  */
 public function shouldAllowGetPreviouslySetResult()
 {
     $request = new Convert(new \stdClass(), 'array');
     $request->setResult($result = new \stdClass());
     $this->assertSame($result, $request->getResult());
 }