/** * Tries to process a payment through Paymill * * @param FreePaymentMethod $paymentMethod Payment method * * @return FreePaymentManager Self object */ public function processPayment(FreePaymentMethod $paymentMethod) { /** * At this point, order must be created given a card, and placed in PaymentBridge * * So, $this->paymentBridge->getOrder() must return an object */ $this->paymentEventDispatcher->notifyPaymentOrderLoad($this->paymentBridge, $paymentMethod); /** * Order exists right here */ $this->paymentEventDispatcher->notifyPaymentOrderCreated($this->paymentBridge, $paymentMethod); /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); /** * Payment paid successfully * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); return $this; }
/** * Tries to process a payment through Bankwire * * @return BankwireManager Self object * * @throws PaymentOrderNotFoundException */ public function processPayment() { $bankwireMethod = $this->bankwireMethodWrapper->getBankwireMethod(); /** * At this point, order must be created given a cart, and placed in PaymentBridge * * So, $this->paymentBridge->getOrder() must return an object */ $this->paymentEventDispatcher->notifyPaymentOrderLoad($this->paymentBridge, $bankwireMethod); /** * Order Not found Exception must be thrown just here */ if (!$this->paymentBridge->getOrder()) { throw new PaymentOrderNotFoundException(); } /** * Order exists right here */ $this->paymentEventDispatcher->notifyPaymentOrderCreated($this->paymentBridge, $bankwireMethod); /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $bankwireMethod); return $this; }
/** * Executes the payment : DoExpressCheckoutPayment * */ public function processPayment(PaypalExpressCheckoutMethod $paymentMethod) { $orderParameters = $paymentMethod->getSomeExtraData(); $this->paypalWrapper->request('DoExpressCheckoutPayment', $orderParameters); $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); if ($this->getPaymentStatus($this->paypalWrapper) == 'PaymentActionCompleted') { $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paypalMethod); } else { $this->paymentEventDispatcher->notifyPaymentOrderFail($paymentBridge, $paypalMethod); } return $this->getPaymentStatus(); }
/** * Given a paymillTransaction response, as an array, prform desired operations * * @param string $apiResponse Api response * @param BanwireMethod $paymentMethod Payment method * * @return BanwireManager Self object * * @throws PaymentException */ private function processTransaction($apiResponse, BanwireMethod $paymentMethod) { $banwireParams = json_decode($apiResponse); if (isset($banwireParams->order_id)) { $paymentMethod->setBanwireTransactionId($banwireParams->order_id); } if (isset($banwireParams->referencia)) { $paymentMethod->setBanwireReference($banwireParams->referencia); } /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); if ($banwireParams->response == 'ok') { $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); } else { $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod); throw new PaymentException(); } /** * Log the response of gateway */ return $this; }
/** * Given a paymillTransaction response, as an array, prform desired operations * * @param array $autWS * @param PagosonlineMethod $paymentMethod Payment method * * @return PagosonlineManager Self object * * @throws PaymentException */ private function processTransaction($autWS, PagosonlineMethod $paymentMethod) { /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); $this->logger->addInfo($paymentMethod->getPaymentName() . 'processTransaction', get_object_vars($autWS)); /** * if pagosonline return code 15 o 9994 the order status is pending */ if (in_array($autWS->codigoRespuesta, array('15', '9994'))) { //payment is still pending nothing to do } elseif ($autWS->codigoRespuesta == 1) { $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); } else { $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod); throw new PaymentException(); } /** * Log the response of gateway */ return $this; }
/** * Captures a previously authorized transaction. * This will only work for transaction whose * "transaction type" is "1" and not "A". * * @param $amount amount to be charged in cents * @param $redsysTransactionId redsys transaction id (DS_ORDER) * * @throws PaymentException */ public function captureTransaction($amount, $redsysTransactionId) { /* * Captures a previously authorized transaction */ $this->transactionType = 2; $entryData = sprintf(self::CAPTURE_MESSAGE, $amount, $redsysTransactionId, $this->merchantCode, $this->currency, $this->transactionType, $this->merchantTerminal); $this->response = sprintf(self::ROOT_MESSAGE, $entryData, $this->signTransactionMac256($redsysTransactionId, $entryData)); $method = new RedsysApiMethod(); try { $r = $this->_callSoap(); } catch (\Exception $e) { /* The Soap call failed */ $this->eventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $method); throw new PaymentException($e->getMessage()); } $this->eventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $method); if (!$this->isAuthorized($r)) { $this->paymentBridge->setError($this->getError($r)); $this->paymentBridge->setErrorCode($this->getErrorCode($r)); $method->setTransactionResponse($this->getError($r)); /* Payment capture has been refused */ $this->eventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $method); throw new PaymentException($this->getErrorCode($r)); } else { /** * Payment OK */ $this->eventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $method); } }
/** * Processes the POST request sent by Redsys * * @param array $parameters Array with response parameters * * @return RedsysManager Self object * * @throws InvalidSignatureException * @throws ParameterNotReceivedException * @throws PaymentException */ public function processResult(array $parameters) { //Check we receive all needed parameters $this->checkResultParameters($parameters); $redsysMethod = new RedsysMethod(); $dsSignature = $parameters['Ds_Signature']; $dsParams = $parameters['Ds_MerchantParameters']; $dsVersion = $parameters['Ds_SignatureVersion']; $paramsDecoded = base64_decode(strtr($dsParams, '-_', '+/')); $this->varsPay = json_decode($paramsDecoded, true); $dsResponse = $this->varsPay['Ds_Response']; $dsAmount = $this->varsPay['Ds_Amount']; $dsOrder = $this->varsPay['Ds_Order']; $dsMerchantCode = $this->varsPay['Ds_MerchantCode']; $dsCurrency = $this->varsPay['Ds_Currency']; $dsDate = $this->varsPay['Ds_Date']; $dsHour = $this->varsPay['Ds_Hour']; $dsSecurePayment = $this->varsPay['Ds_SecurePayment']; $dsCardCountry = $this->varsPay['Ds_Card_Country']; $dsAuthorisationCode = $this->varsPay['Ds_AuthorisationCode']; $dsConsumerLanguage = $this->varsPay['Ds_ConsumerLanguage']; $dsCardType = array_key_exists('Ds_Card_Type', $this->varsPay) ? $this->varsPay['Ds_Card_Type'] : ''; $dsMerchantData = array_key_exists('Ds_MerchantData', $this->varsPay) ? $this->varsPay['Ds_MerchantData'] : ''; if ($dsSignature != $this->expectedSignature($dsParams)) { throw new InvalidSignatureException(); } /** * Adding transaction information to PaymentMethod * * This information is only available in PaymentOrderSuccess event */ $redsysMethod->setDsResponse($dsResponse)->setDsAuthorisationCode($dsAuthorisationCode)->setDsCardCountry($dsCardCountry)->setDsCardType($dsCardType)->setDsConsumerLanguage($dsConsumerLanguage)->setDsDate($dsDate)->setDsHour($dsHour)->setDsSecurePayment($dsSecurePayment)->setDsOrder($dsOrder); /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $redsysMethod); /** * when a transaction is successful, $Ds_Response has a value between 0 and 99 */ if (!$this->transactionSuccessful($dsResponse)) { /** * Payment paid failed * * Paid process has ended failed */ $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $redsysMethod); throw new PaymentException(); } /** * Payment paid successfully * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $redsysMethod); return $this; }
/** * Processes the POST request sent by Redsys. * * @param array $parameters Array with response parameters * * @return RedsysManager Self object * * @throws InvalidSignatureException Invalid signature * @throws ParameterNotReceivedException Invalid parameters * @throws PaymentException Payment exception */ public function processResult(array $parameters) { $this->checkResultParameters($parameters); $redsysMethod = new RedsysMethod(); $dsSignature = $parameters['Ds_Signature']; $dsResponse = $parameters['Ds_Response']; $dsAmount = $parameters['Ds_Amount']; $dsOrder = $parameters['Ds_Order']; $dsMerchantCode = $parameters['Ds_MerchantCode']; $dsCurrency = $parameters['Ds_Currency']; $dsSecret = $this->secretKey; $dsDate = $parameters['Ds_Date']; $dsHour = $parameters['Ds_Hour']; $dsSecurePayment = $parameters['Ds_SecurePayment']; $dsCardCountry = $parameters['Ds_Card_Country']; $dsAuthorisationCode = $parameters['Ds_AuthorisationCode']; $dsConsumerLanguage = $parameters['Ds_ConsumerLanguage']; $dsCardType = array_key_exists('Ds_Card_Type', $parameters) ? $parameters['Ds_Card_Type'] : ''; if ($dsSignature != $this->expectedSignature($dsAmount, $dsOrder, $dsMerchantCode, $dsCurrency, $dsResponse, $dsSecret)) { throw new InvalidSignatureException(); } /** * Adding transaction information to PaymentMethod. * * This information is only available in PaymentOrderSuccess event */ $redsysMethod->setDsResponse($dsResponse)->setDsAuthorisationCode($dsAuthorisationCode)->setDsCardCountry($dsCardCountry)->setDsCardType($dsCardType)->setDsConsumerLanguage($dsConsumerLanguage)->setDsDate($dsDate)->setDsHour($dsHour)->setDsSecurePayment($dsSecurePayment)->setDsOrder($dsOrder); /** * Payment paid done. * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $redsysMethod); /** * when a transaction is successful, $Ds_Response has a * value between 0 and 99. */ if (!$this->transactionSuccessful($dsResponse)) { /** * Payment paid failed. * * Paid process has ended failed */ $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $redsysMethod); throw new PaymentException(); } /** * Payment paid successfully. * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $redsysMethod); return $this; }
/** * Processes the POST request sent by Redsys * * @param array $parameters Array with response parameters * * @return RedsysManager Self object * * @throws InvalidSignatureException * @throws ParameterNotReceivedException * @throws PaymentException */ public function processResult(array $response) { //Check we receive all needed parameters $Ds_Signature = $response['Ds_Signature']; $parameters = (array) json_decode(base64_decode($response['Ds_MerchantParameters'])); $parameters = array_change_key_case($parameters, CASE_UPPER); $this->checkResultParameters($parameters); $redsysMethod = new RedsysMethod(); $dsSignature = $Ds_Signature; $dsResponse = $parameters['DS_RESPONSE']; $dsAmount = $parameters['DS_AMOUNT']; $dsOrder = $parameters['DS_ORDER']; $dsMerchantCode = $parameters['DS_MERCHANTCODE']; $dsCurrency = $parameters['DS_CURRENCY']; $dsSecret = $this->secretKey; $dsDate = $parameters['DS_DATE']; $dsHour = $parameters['DS_HOUR']; $dsSecurePayment = $parameters['DS_SECUREPAYMENT']; $dsCardCountry = $parameters['DS_CARD_COUNTRY']; $dsAuthorisationCode = $parameters['DS_AUTHORISATIONCODE']; $dsConsumerLanguage = $parameters['DS_CONSUMERLANGUAGE']; $dsCardType = array_key_exists('DS_CARD_TYPE', $parameters) ? $parameters['DS_CARD_TYPE'] : ''; $dsMerchantData = array_key_exists('DS_MERCHANTDATA', $parameters) ? $parameters['DS_MERCHANTDATA'] : ''; $internalSignature = $this->redsysSignature->sign($dsOrder, $dsSecret, $response['Ds_MerchantParameters']); /** * Validate if signature from Redsys and our signature are identical, */ $this->redsysSignature->checkSign($dsSignature, $internalSignature); /** * Adding transaction information to PaymentMethod * * This information is only available in PaymentOrderSuccess event */ $redsysMethod->setDsResponse($dsResponse)->setDsAuthorisationCode($dsAuthorisationCode)->setDsCardCountry($dsCardCountry)->setDsCardType($dsCardType)->setDsConsumerLanguage($dsConsumerLanguage)->setDsDate($dsDate)->setDsHour($dsHour)->setDsSecurePayment($dsSecurePayment)->setDsOrder($dsOrder); /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $redsysMethod); /** * when a transaction is successful, $Ds_Response has a value between 0 and 99 */ $this->transactionSuccessful($dsResponse, $redsysMethod); /** * Payment paid successfully * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $redsysMethod); return $this; }
/** * Collect callback data after payment process * * @param array $response Response data * * @throws PaymentAmountsNotMatchException * @throws PaymentException * * @return GoogleWalletManager Self object */ public function processPayment($response) { $paymentMethod = new GoogleWalletMethod(); $paymentMethod->setTransactionResponse($response); if (in_array('orderId', $response)) { $paymentMethod->setTransactionId($response['orderId'])->setTransactionStatus('paid'); $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); } else { $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod); throw new PaymentException(); } return $this; }
/** * Tries to process a payment through Stripe. * * @param StripeMethod $paymentMethod Payment method * @param float $amount Amount * * @throws PaymentAmountsNotMatchException * @throws PaymentException * * @return StripeManager Self object */ public function processPayment(StripeMethod $paymentMethod, $amount) { /** * check and set payment data. */ $chargeParams = $this->prepareData($paymentMethod, $amount); /** * make payment. */ $transaction = $this->transactionFactory->create($chargeParams); /** * Payment paid done. * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); /** * when a transaction is successful, it is marked as 'closed'. */ if ($transaction['paid'] != 1) { /** * Payment paid failed. * * Paid process has ended failed */ $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod); throw new PaymentException(); } $paymentMethod->setTransactionId($transaction['id'])->setTransactionStatus('paid')->setTransactionResponse($transaction); /** * Payment paid successfully. * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); return $this; }
/** * Process Paypal IPN response to payment. * * When the IPN mesage is validated, a payment success event * should be dispatched. * * @param int $orderId Order Id * @param array $parameters parameter array coming from Paypal IPN notification * * @throws ParameterNotReceivedException * @throws PaymentException */ public function processPaypalIPNMessage($orderId, array $parameters) { /** * Retrieving the order object. */ $order = $this->paymentBridge->findOrder($orderId); if (!$order) { throw new PaymentOrderNotFoundException(sprintf('Order #%s not found', $orderId)); } $this->paymentBridge->setOrder($order); /** * Check that we receive the mandatory parameters. */ $this->checkResultParameters($parameters); /** * Initializing PaypalWebCheckoutMethod, which is * an object representation of the payment information * coming from the payment processor. */ $paypalMethod = $this->paymentMethodFactory->create($parameters['mc_gross'], $parameters['payment_status'], $parameters['notify_version'], $parameters['payer_status'], $parameters['business'], null, $parameters['verify_sign'], $parameters['payer_email'], $parameters['txn_id'], $parameters['payment_type'], $parameters['receiver_email'], null, $parameters['txn_type'], null, $parameters['mc_currency'], null, $parameters['test_ipn'], $parameters['ipn_track_id']); /** * Notifying payment.done, which means that the * payment has been received, although we still * do not know if it is succesful or not. * Listening fot this event is useful when one * wants to record transaction informations. */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paypalMethod); /** * Check if the transaction is successful. */ if (!$this->transactionSuccessful($parameters)) { $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paypalMethod); throw new PaymentException(); } /** * Payment paid successfully. * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paypalMethod); }
/** * Tries to process a payment through Authorizenet * * @param AuthorizenetMethod $paymentMethod Payment method * * @throws PaymentAmountsNotMatchException * @throws PaymentException * * @return AuthorizenetManager Self object */ public function processPayment(AuthorizenetMethod $paymentMethod) { /** * check and set payment data */ $this->prepareData($paymentMethod); /** * make payment */ $transaction = $this->transactionWrapper->create($this->chargeParams); /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); /** * when a transaction is successful, it is marked as 'closed' */ if (!isset($transaction[2]) || $transaction[2] != 1) { /** * Payment paid failed * * Paid process has ended failed */ $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod); throw new PaymentException(); } $paymentMethod->setTransactionId($transaction[37])->setTransactionStatus('paid')->setTransactionResponse($transaction); /** * Payment paid successfully * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); return $this; }
/** * Given a paymillTransaction response, as an array, prform desired operations * * @param Transaction $transaction Transaction * @param PaymillMethod $paymentMethod Payment method * * @return PaymillManager Self object * * @throws PaymentException */ private function processTransaction(Transaction $transaction, PaymillMethod $paymentMethod) { /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); /** * when a transaction is successful, it is marked as 'closed' */ $transactionStatus = $transaction->getStatus(); if (empty($transactionStatus) || $transactionStatus != 'closed') { /** * Payment paid failed * * Paid process has ended failed */ $paymentMethod->setTransaction($transaction); $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod); throw new PaymentException(); } /** * Adding to PaymentMethod transaction information * * This information is only available in PaymentOrderSuccess event */ $paymentMethod->setTransactionId($transaction->getId())->setTransactionStatus($transactionStatus)->setTransaction($transaction); /** * Payment paid successfully * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); return $this; }
/** * * @param $result \soap response * @param DineromailApiMethod $paymentMethod Payment method * * @throws \PaymentSuite\PaymentCoreBundle\Exception\PaymentException * @return DineromailApiMethod Self object * */ private function processTransaction($result, DineromailApiMethod $paymentMethod) { $this->logger->addInfo($paymentMethod->getPaymentName() . 'processTransaction Result', get_object_vars($result)); $paymentMethod->setDineromailApiReference($result->MerchantTransactionId); $paymentMethod->setDineromailApiTransactionId($result->TransactionId); /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); switch ($result->Status) { case 'OK': case 'COMPLETED': $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); break; case 'PENDING': break; default: $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod); throw new PaymentException(); } return $this; }
/** * Testing notifyPaymentDone. */ public function testNotifyPaymentOrderDone() { $this->eventDispatcher->expects($this->once())->method('dispatch')->with($this->equalTo(PaymentCoreEvents::PAYMENT_ORDER_DONE), $this->isInstanceOf('PaymentSuite\\PaymentCoreBundle\\Event\\PaymentOrderDoneEvent')); $paymentEventDispatcher = new PaymentEventDispatcher($this->eventDispatcher); $paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $this->paymentMethod); }