/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $form = $this->createPurchaseForm(); $form->handleRequest($this->container->get('request')); if ($form->isValid()) { $data = $form->getData(); /** @var Cart $cart */ $cart = $request->getModel(); $cartStorage = $this->container->get('payum')->getStorage($cart); $paymentStorage = $this->container->get('payum')->getStorage('Acme\\PaymentBundle\\Model\\PaymentDetails'); /** @var $payment PaymentDetails */ $payment = $paymentStorage->create(); $payment['amount'] = $cart->getPrice(); $payment['card_num'] = new SensitiveValue($data['card_number']); $payment['exp_date'] = new SensitiveValue($data['card_expiration_date']); $paymentStorage->update($payment); $cart->setDetails($payment); $cartStorage->update($cart); $request->setModel($payment); $this->gateway->execute($request); return; } throw new HttpResponse(new Response($this->container->get('templating')->render('AcmeOtherExamplesBundle:CartExamples:_submit_credit_card.html.twig', array('form' => $form->createView())))); }
/** * {@inheritDoc} * * @param Capture $request */ public function execute($request) { if (!$this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $details = ArrayObject::ensureArrayObject($request->getModel()); if ($details['_status']) { return; } if (false == $details['clientIp']) { $this->payment->execute($httpRequest = new GetHttpRequest); $details['clientIp'] = $httpRequest->clientIp; } if (isset($details['_completeCaptureRequired'])) { $response = $this->gateway->completePurchase($details->toUnsafeArray())->send(); unset($details['_completeCaptureRequired']); } else { if (false == $details->validateNotEmpty(array('card'), false) && false == $details->validateNotEmpty(array('cardReference'), false)) { try { $this->payment->execute($creditCardRequest = new ObtainCreditCard); $card = $creditCardRequest->obtain(); $details['card'] = new SensitiveValue(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.'); } } $response = $this->gateway->purchase($details->toUnsafeArray())->send(); } if ($response->isRedirect()) { $details['_completeCaptureRequired'] = 1; if ($response->getRedirectMethod() == 'POST') { throw new HttpPostRedirect($response->getRedirectUrl(), $response->getRedirectData()); } else { throw new HttpRedirect($response->getRedirectUrl()); } } $details['_reference'] = $response->getTransactionReference(); $details['_status'] = $response->isSuccessful() ? 'captured' : 'failed'; $details['_status_code'] = $response->getCode(); $details['_status_message'] = $response->isSuccessful() ? '' : $response->getMessage(); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request ObtainCreditCard */ if (!$this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } if (!$this->httpRequest) { throw new LogicException('The action can be run only when http request is set.'); } $form = $this->createCreditCardForm(); $form->handleRequest($this->httpRequest); if ($form->isSubmitted()) { /** @var CreditCardInterface $card */ $card = $form->getData(); $card->secure(); if ($form->isValid()) { $request->set($card); return; } } $renderTemplate = new RenderTemplate($this->templateName, array( 'form' => $form->createView(), )); $this->payment->execute($renderTemplate); throw new HttpResponse(new Response($renderTemplate->getResult(), 200, array( 'Cache-Control' => 'no-store, no-cache, max-age=0, post-check=0, pre-check=0', 'Pragma' => 'no-cache', ))); }
/** * {@inheritdoc} */ public function execute($request) { if (!$this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $options = ArrayObject::ensureArrayObject($request->getModel()); if ($options['_status']) { return; } if (isset($options['_completeCaptureRequired'])) { unset($options['_completeCaptureRequired']); $response = $this->gateway->completePurchase($options->toUnsafeArray())->send(); } else { $response = $this->gateway->purchase($options->toUnsafeArray())->send(); } if ($response->isRedirect()) { $options['_completeCaptureRequired'] = 1; if ($response->getRedirectMethod() == 'POST') { throw new HttpPostRedirect($response->getRedirectUrl(), $response->getRedirectData()); } else { throw new HttpRedirect($response->getRedirectUrl()); } } $options['_reference'] = $response->getTransactionReference(); $options['_status'] = $response->isSuccessful() ? 'success' : 'failed'; $options['_status_code'] = $response->getCode(); $options['_status_message'] = $response->isSuccessful() ? '' : $response->getMessage(); }
/** * {@inheritdoc} */ public function execute($request) { /** @var $request GetStatusInterface */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); if (null === $model['response_code']) { $request->markNew(); return; } if (\AuthorizeNetAIM_Response::APPROVED == $model['response_code']) { $request->markSuccess(); return; } if (\AuthorizeNetAIM_Response::DECLINED == $model['response_code']) { $request->markCanceled(); return; } if (\AuthorizeNetAIM_Response::ERROR == $model['response_code']) { $request->markFailed(); return; } if (\AuthorizeNetAIM_Response::HELD == $model['response_code']) { $request->markPending(); return; } $request->markUnknown(); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request GetStatusInterface */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); if ($model['error']) { $request->markFailed(); return; } if (false == $model['card']) { $request->markNew(); return; } // means we have only received a stripe token but have not done a payment. if (is_string($model['card'])) { $request->markPending(); return; } if (is_array($model['card']) && $model['captured'] && $model['paid']) { $request->markSuccess(); return; } $request->markUnknown(); }
/** * {@inheritDoc} * * @param $request Notify */ public function execute($request) { if (!$this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $this->payment->execute($httpRequest = new GetHttpRequest()); $details = $httpRequest->query; if (!$this->api->verifyHash($details)) { throw new BadRequestHttpException('Hash cannot be verified.'); } if (empty($details['ORDERID'])) { throw new BadRequestHttpException('Order id cannot be guessed'); } $payment = $this->paymentRepository->findOneBy(array($this->identifier => $details['ORDERID'])); if (null === $payment) { throw new BadRequestHttpException('Payment cannot be retrieved.'); } if ((int) $details['AMOUNT'] !== $payment->getAmount()) { throw new BadRequestHttpException('Request amount cannot be verified against payment amount.'); } // Actually update payment details $details = array_merge($payment->getDetails(), $details); $payment->setDetails($details); $status = new GetStatus($payment); $this->payment->execute($status); $nextState = $status->getValue(); $this->updatePaymentState($payment, $nextState); $this->objectManager->flush(); throw new HttpResponse(new Response('OK', 200)); }
/** * {@inheritdoc} */ public function execute($request) { /** @var $request CaptureRequest */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); if (false == $model['PAYMENTREQUEST_0_PAYMENTACTION']) { $model['PAYMENTREQUEST_0_PAYMENTACTION'] = Api::PAYMENTACTION_SALE; } if (false == $model['TOKEN']) { if (false == $model['RETURNURL'] && $request instanceof SecuredCaptureRequest) { $model['RETURNURL'] = $request->getToken()->getTargetUrl(); } if (false == $model['CANCELURL'] && $request instanceof SecuredCaptureRequest) { $model['CANCELURL'] = $request->getToken()->getTargetUrl(); } $this->payment->execute(new SetExpressCheckoutRequest($model)); $this->payment->execute(new AuthorizeTokenRequest($model)); } $this->payment->execute(new SyncRequest($model)); if ($model['PAYERID'] && Api::CHECKOUTSTATUS_PAYMENT_ACTION_NOT_INITIATED == $model['CHECKOUTSTATUS'] && $model['PAYMENTREQUEST_0_AMT'] > 0) { $this->payment->execute(new DoExpressCheckoutPaymentRequest($model)); } $this->payment->execute(new SyncRequest($model)); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request Capture */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($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 { $this->payment->execute($obtainCreditCard = new ObtainCreditCard()); $card = $obtainCreditCard->obtain(); $model['EXPDATE'] = new SensitiveValue($card->getExpireAt()->format('my')); $model['ACCT'] = $card->getNumber(); $model['CVV2'] = $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.'); } } $buzzRequest = new Request(); $buzzRequest->setFields($model->toUnsafeArray()); $response = $this->api->doPayment($buzzRequest); $model->replace($response); }
/** * {@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 \Payum\Core\Request\Capture */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = new ArrayObject($request->getModel()); if (null !== $model['EXECCODE']) { return; } $cardFields = array('CARDCODE', 'CARDCVV', 'CARDVALIDITYDATE', 'CARDFULLNAME'); if (false == $model->validateNotEmpty($cardFields, false) && false == $model['ALIAS']) { try { $creditCardRequest = new ObtainCreditCard(); $this->payment->execute($creditCardRequest); $card = $creditCardRequest->obtain(); $model['CARDVALIDITYDATE'] = new SensitiveValue($card->getExpireAt()->format('m-y')); $model['CARDCODE'] = $card->getNumber(); $model['CARDFULLNAME'] = $card->getHolder(); $model['CARDCVV'] = $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.'); } $response = $this->api->payment($model->toUnsafeArray()); $model->replace((array) $response->getContentJson()); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request StatusRequestInterface */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } /** @var PaymentInterface $payment */ $payment = $request->getModel(); if (in_array($payment->getState(), array(PaymentInterface::STATE_APPROVED, PaymentInterface::STATE_DEPOSITED))) { $request->markSuccess(); return; } if (in_array($payment->getState(), array(PaymentInterface::STATE_DEPOSITING))) { $request->markPending(); return; } if (in_array($payment->getState(), array(PaymentInterface::STATE_CANCELED))) { $request->markCanceled(); return; } if (in_array($payment->getState(), array(PaymentInterface::STATE_EXPIRED))) { $request->markExpired(); return; } if (in_array($payment->getState(), array(PaymentInterface::STATE_FAILED))) { $request->markFailed(); return; } if (in_array($payment->getState(), array(PaymentInterface::STATE_NEW, PaymentInterface::STATE_APPROVING))) { $request->markNew(); return; } $request->markUnknown(); }
/** * {@inheritdoc} */ public function execute($request) { /** @var $request Capture */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); if (null != $model['response_code']) { return; } if (false == $model->validateNotEmpty(array('card_num', 'exp_date'), false)) { try { $this->payment->execute($obtainCreditCard = new ObtainCreditCard()); $card = $obtainCreditCard->obtain(); $model['exp_date'] = new SensitiveValue($card->getExpireAt()->format('m/y')); $model['card_num'] = new SensitiveValue($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 \Payum\Core\Request\CaptureRequest */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } /** @var Payment $model */ $model = $request->getModel(); if (false == isset($model->state) && isset($model->payer->payment_method) && 'paypal' == $model->payer->payment_method) { $model->create($this->api); foreach ($model->links as $link) { if ($link->rel == 'approval_url') { throw new RedirectUrlInteractiveRequest($link->href); } } } if (false == isset($model->state) && isset($model->payer->payment_method) && 'credit_card' == $model->payer->payment_method) { $model->create($this->api); } if (true == isset($model->state) && isset($model->payer->payment_method) && 'paypal' == $model->payer->payment_method) { $execution = new PaymentExecution(); $execution->payer_id = $_GET['PayerID']; //Execute the payment $model->execute($execution, $this->api); } }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request \Payum\Core\Request\GetStatusInterface */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); //TODO: It may be not correct for all cases. This does NOT indicate wether the transaction requested was successful, only wether the request was carried out successfully. if ($model['errorCode'] && OrderApi::ERRORCODE_OK != $model['errorCode']) { $request->markFailed(); return; } if (is_numeric($model['agreementStatus']) && AgreementApi::AGREEMENTSTATUS_NOTVERIFIED == $model['agreementStatus']) { $request->markNew(); return; } if (is_numeric($model['agreementStatus']) && AgreementApi::AGREEMENTSTATUS_VERIFIED == $model['agreementStatus']) { $request->markSuccess(); return; } if (is_numeric($model['agreementStatus']) && AgreementApi::AGREEMENTSTATUS_DELETED == $model['agreementStatus']) { $request->markCanceled(); return; } $request->markUnknown(); }
/** * {@inheritDoc} */ public function execute($request) { if (!$this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); if ($model['_status']) { return; } if (false == $model->validateNotEmpty(array('card'), false)) { try { $creditCardRequest = new ObtainCreditCardRequest(); $this->payment->execute($creditCardRequest); $card = $creditCardRequest->obtain(); $firstName = $lastName = ''; list($firstName, $lastName) = explode(' ', $card->getHolder(), 1); $model['card'] = new SensitiveValue(array('number' => $card->getNumber(), 'cvv' => $card->getSecurityCode(), 'expiryMonth' => $card->getExpireAt()->format('m'), 'expiryYear' => $card->getExpireAt()->format('y'), 'firstName' => $firstName, 'lastName' => $lastName)); } catch (RequestNotSupportedException $e) { throw new LogicException('Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCardRequest request.'); } } $response = $this->gateway->purchase($model->toUnsafeArray())->send(); $model['_reference'] = $response->getTransactionReference(); $model['_status'] = $response->isSuccessful() ? 'success' : 'failed'; $model['_status_code'] = $response->getCode(); $model['_status_message'] = $response->isSuccessful() ? '' : $response->getMessage(); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request GetStatusInterface */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); //TODO: It may be not correct for all cases. This does NOT indicate wether the transaction requested was successful, only wether the request was carried out successfully. if ($model['errorCode'] && OrderApi::ERRORCODE_OK != $model['errorCode']) { $request->markFailed(); return; } if (null === $model['transactionStatus']) { $request->markNew(); return; } if (AgreementApi::PURCHASEOPERATION_SALE == $model['purchaseOperation'] && OrderApi::TRANSACTIONSTATUS_SALE == $model['transactionStatus']) { $request->markSuccess(); return; } if (AgreementApi::PURCHASEOPERATION_AUTHORIZATION == $model['purchaseOperation'] && OrderApi::TRANSACTIONSTATUS_AUTHORIZE == $model['transactionStatus']) { $request->markSuccess(); return; } $request->markFailed(); }
/** * @test */ public function shouldCreateWithActionAndObjectRequest() { $action = $this->getMock('Payum\\Core\\Action\\ActionInterface', array(), array(), 'Mock_Action24'); $exception = RequestNotSupportedException::createActionNotSupported($action, new \stdClass()); $this->assertInstanceOf('Payum\\Core\\Exception\\RequestNotSupportedException', $exception); $this->assertEquals('Action Mock_Action24 is not supported the request stdClass.', $exception->getMessage()); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request \Payum\Core\Request\Capture */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $this->payment->execute(new AutoPayAgreement($request->getModel())); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request RenderTemplate */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $request->setResult($this->twig->render($request->getTemplateName(), array_replace(array('layout' => $this->layout), $request->getContext()))); }
/** * {@inheritdoc} */ public function execute($request) { /** @var $request GetStatusInterface */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $request->markNew(); }
/** * {@inheritdoc} */ public function execute($request) { /** @var $request NotifyRequest */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $this->payment->execute(new SyncRequest($request->getModel())); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request ModelAwareInterface */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $request->setModel($request->getModel()->getDetails()); $this->payment->execute($request); }
/** * {@inheritdoc} */ public function execute($request) { /** @var $request CreateRecurringPaymentProfileRequest */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); $model->validateNotEmpty(array('TOKEN', 'PROFILESTARTDATE', 'DESC', 'BILLINGPERIOD', 'BILLINGFREQUENCY', 'AMT', 'CURRENCYCODE')); $model->replace($this->api->createRecurringPaymentsProfile((array) $model)); }
/** * @test */ public function shouldCreateWithActionAndObjectRequest() { $request = new \stdClass(); $action = $this->getMock(ActionInterface::class, array(), array(), 'Mock_Action24'); $exception = RequestNotSupportedException::createActionNotSupported($action, $request); $this->assertInstanceOf(RequestNotSupportedException::class, $exception); $this->assertStringStartsWith('Action Mock_Action24 is not supported the request stdClass.', $exception->getMessage()); $this->assertSame($request, $exception->getRequest()); $this->assertSame($action, $exception->getAction()); }
/** * {@inheritdoc} */ public function execute($request) { /** @var $request CreateRecurringPaymentProfileRequest */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); $model->validateNotEmpty('PROFILEID'); $model->replace($this->api->getRecurringPaymentsProfileDetails(array('PROFILEID' => $model['PROFILEID']))); }
/** * [@inheritdoc} */ public function execute($request) { /** @var $request \Payum\Paypal\ExpressCheckout\Nvp\Request\Api\ManageRecurringPaymentsProfileStatusRequest */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); $model->validateNotEmpty(array('PROFILEID', 'ACTION')); $model->replace($this->api->manageRecurringPaymentsProfileStatus((array) $model)); }
/** * {@inheritdoc} */ public function execute($request) { /** @var $request \Payum\Core\Request\Sync */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } /** @var Payment $model */ $model = $request->getModel(); $payment = Payment::get($model->id); $model->fromArray($payment->toArray()); }
/** * {@inheritDoc} */ public function execute($request) { /** @var $request CheckAgreement */ if (false == $this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $model = ArrayObject::ensureArrayObject($request->getModel()); $model->validateNotEmpty(array('agreementRef')); $result = $this->api->check((array) $model); $model->replace($result); }
/** * {@inheritdoc} */ public function execute($request) { if (!$this->supports($request)) { throw RequestNotSupportedException::createActionNotSupported($this, $request); } $payment = $request->getModel(); if ($payment->getDetails()) { return; } $payment->setDetails(array(Constants::FIELD_PAID => false)); }