public function deposit(jmsPaymentMethodData $data, $retry = false) { try { $result = $this->getDispatcher()->sessionApprove($this->getAccessKey(), $this->getTestMode(), $data['external_reference_number']); $data->setResponseCode($result['status']); if ($result['status'] === 'APPROVED') { $data->setProcessedAmount($data->getAmount()); } } catch (Exception $e) { $data->setReasonCode($e->getMessage()); $e = jmsPaymentException::fromException($e); $e->setPaymentMethodData($data); throw $e; } }
/** * Deposits a transaction. This method is not intended to call any * api belonging to 4b system as this api does not exist. The first * action for depositing has to be a POST submission to an URL outside * of the online shop pages where the purchaser has to fill payment info. * When this is done 4b server calls in return online shop url. * You have to connect that url with this method. * You can inform 4b about the url that leads to this method in the * field labeled: "URL que graba el resultado en la BD del comercio" * https://tpv.4b.es/config * * @see plugins/jmsPaymentPlugin/lib/method/jmsPaymentMethod#deposit($data, $retry) */ public function deposit(jmsPaymentMethodData $data, $retry = false) { //If this is not called from 4b systems we want to launch a user interaction exception //Check call originated from 4b simulation or production servers. $caller_address = sfContext::getInstance()->getRequest()->getRemoteAddress(); //This call is far from the paymentDemo sfAction //to not taint the 'general' logic implemented there. $production_ip = $this->getProductionIp(); $simulation_ip = $this->getSimulationIp(); //This block is going to be executed when call is from 'shop' pages and //4b pages to be filled by the user are going to be shown as result. if ($caller_address != $production_ip && $caller_address != $simulation_ip) { //call to deposit not from 4b servers $production_url = $this->getProductionUrl(); $simulation_url = $this->getSimulationUrl(); $_4b_conection_url = !$this->isDebug() ? $production_url : $simulation_url; // throw $exception = new jmsPaymentUserActionRequiredException(new jmsPaymentUserActionVisitURL($_4b_conection_url)); $data->setValue('transaction_from_ip', $caller_address); $exception->setPaymentMethodData($data); throw $exception; } //This block is going to be executed when call is from 4b server $amount_value = $data->getAmount(); if ($data->getValue('transaction_result') == 1) { //Success $data->setResponseCode($data->getValue('transaction_id')); $data->setReasonCode('Approval with 4b approval code: ' . $data->getValue('transaction_approval_code')); $data->setProcessedAmount($amount_value); //Processed amount equals requested. } else { //Failed $data->setResponseCode($data->getValue('transaction_error_code')); $data->setReasonCode($data->getValue('transaction_error_description')); $e = new jmsPaymentException('Payment could not be completed. Reason: ' . $data->getReasonCode()); $e->setPaymentMethodData($data); throw $e; } }
/** * Updates the persistent instances with the returned data * @param jmsPaymentMethodData $data */ private function updateFromPaymentMethodData(jmsPaymentMethodData $data) { $this->response_code = $data->getResponseCode(); $this->reason_code = $data->getReasonCode(); $this->processed_amount = $data->getProcessedAmount(); $dataContainer = $this->Payment->DataContainer; foreach ($data->getExtendedValues() as $name => $value) { $dataContainer->{$name} = $value; } $this->Payment->DataContainer->save(); }
/** * Deposits a transaction * @throws jmsPaymentApprovalExpiredException * @throws jmsPaymentCommunicationException * @see plugins/jmsPaymentPlugin/lib/method/jmsPaymentMethod#deposit($data, $retry) */ public function deposit(jmsPaymentMethodData $data, $retry = false) { $amount = PayPal::getType('BasicAmountType'); $amount->setattr('currencyID', $data->getCurrency()); $amount->setval(number_format($data->getAmount(), 2)); $captureRequest = Paypal::getType('DoCaptureRequestType'); $captureRequest->setAmount($amount); $captureRequest->setAuthorizationId($data->getValue('external_reference_number')); $captureRequest->setCompleteType('Complete'); if ($data->hasValue('note')) { $captureRequest->setNote($data->getValue('note')); } $result = $this->getCallerServices()->DoCapture($captureRequest); if (Pear::isError($result)) { throw new jmsPaymentCommunicationException('Error while capturing payment: ' . $result->getMessage()); } if ($result->Ack !== 'Success') { throw new jmsPaymentCommunicationException('Error ' . $result->Ack . ' while capturing.'); } $response = $result->getDoCaptureResponseDetails(); $paymentInfo = $response->getPaymentInfo(); $data->setResponseCode($paymentInfo->PaymentStatus); $data->setProcessedAmount($data->getAmount()); // process the payment status switch ($paymentInfo->PaymentStatus) { case 'Expired': $e = new jmsPaymentApprovalExpiredException(); $e->setPaymentMethodData($data); throw $e; case 'Completed': return $data; case 'Pending': $e = new jmsPaymentException('Payment is still pending; reason: ' . $paymentInfo->PendingReason); $data->setReasonCode($paymentInfo->PendingReason); $e->setPaymentMethodData($data); throw $e; default: // TODO: Some more processing as to what went wrong exactly $e = new jmsPaymentException('Payment could not be completed. Status: ' . $paymentInfo->PaymentStatus); $e->setPaymentMethodData($data); throw $e; } }