/**
  * Makes payment petition
  *
  * @param parameters The parameters to be sent to the server
  * @param transactionType
  *            The type of the payment transaction
  * @param string $lang language of request see SupportedLanguages class            
  * @return The transaction response to the request sent
  * @throws PayUException
  * @throws InvalidArgumentException
  */
 public static function doPayment($parameters, $transactionType, $lang)
 {
     $requiredAll = array(PayUParameters::REFERENCE_CODE, PayUParameters::DESCRIPTION, PayUParameters::CURRENCY, PayUParameters::VALUE);
     $paymentMethodParameter = CommonRequestUtil::getParameter($parameters, PayUParameters::PAYMENT_METHOD);
     if (array_key_exists(PayUParameters::TOKEN_ID, $parameters)) {
         $requiredTokenId = array(PayUParameters::INSTALLMENTS_NUMBER, PayUParameters::TOKEN_ID);
         $required = array_merge($requiredAll, $requiredTokenId);
     } else {
         if (array_key_exists(PayUParameters::CREDIT_CARD_NUMBER, $parameters)) {
             $requiredCreditCard = array(PayUParameters::INSTALLMENTS_NUMBER, PayUParameters::CREDIT_CARD_NUMBER, PayUParameters::PAYER_NAME, PayUParameters::CREDIT_CARD_EXPIRATION_DATE, PayUParameters::PAYMENT_METHOD);
             $processWithoutCvv2 = PayUPayments::isProcessWithoutCvv2Param($parameters);
             if (!$processWithoutCvv2) {
                 $requiredCreditCard[] = PayUParameters::CREDIT_CARD_SECURITY_CODE;
             }
             $required = array_merge($requiredAll, $requiredCreditCard);
         } else {
             if ($paymentMethodParameter != null && PaymentMethods::isAllowedCashPaymentMethod($paymentMethodParameter)) {
                 $requiredCash = array(PayUParameters::PAYER_NAME, PayUParameters::PAYER_DNI, PayUParameters::PAYMENT_METHOD);
                 $required = array_merge($requiredAll, $requiredCash);
             } else {
                 if ($paymentMethodParameter != null && PaymentMethods::BOLETO_BANCARIO == $paymentMethodParameter) {
                     $requiredBoletoBancario = array(PayUParameters::PAYER_NAME, PayUParameters::PAYER_DNI, PayUParameters::PAYMENT_METHOD, PayUParameters::PAYER_STREET, PayUParameters::PAYER_STREET_2, PayUParameters::PAYER_CITY, PayUParameters::PAYER_STATE, PayUParameters::PAYER_POSTAL_CODE);
                     $required = array_merge($requiredAll, $requiredBoletoBancario);
                 } else {
                     if ($paymentMethodParameter != null) {
                         if (PaymentMethods::isValidPaymentMethod($paymentMethodParameter)) {
                             $paymentMethod = PaymentMethods::getPaymentMethod($paymentMethodParameter);
                             if ($paymentMethod['type'] == PayUPaymentMethodType::CREDIT_CARD) {
                                 throw new InvalidArgumentException("Payment method credit card require at least one of two parameters [" . PayUParameters::CREDIT_CARD_NUMBER . '] or [' . PayUParameters::TOKEN_ID . ']');
                             }
                         }
                         throw new InvalidArgumentException(sprintf("The payment method value %s sent in parameter %s is invalid", $paymentMethodParameter, PayUParameters::PAYMENT_METHOD));
                     } else {
                         throw new InvalidArgumentException(sprintf("The payment method parameter [%s] was not found", PayUParameters::PAYMENT_METHOD));
                     }
                 }
             }
         }
     }
     CommonRequestUtil::validateParameters($parameters, $required);
     $request = RequestPaymentsUtil::buildPaymentRequest($parameters, $transactionType, $lang);
     $payUHttpRequestInfo = new PayUHttpRequestInfo(Environment::PAYMENTS_API, RequestMethod::POST);
     return PayUApiServiceUtil::sendRequest($request, $payUHttpRequestInfo);
 }
Пример #2
0
 /**
  * Makes payment petition
  *
  * @param parameters The parameters to be sent to the server
  * @param transactionType
  *            The type of the payment transaction
  * @param string $lang language of request see SupportedLanguages class            
  * @return The transaction response to the request sent
  * @throws PayUException
  * @throws InvalidArgumentException
  */
 public static function doPayment($parameters, $transactionType, $lang)
 {
     $requiredAll = array(PayUParameters::REFERENCE_CODE, PayUParameters::DESCRIPTION, PayUParameters::CURRENCY, PayUParameters::VALUE);
     $paymentMethodParameter = CommonRequestUtil::getParameter($parameters, PayUParameters::PAYMENT_METHOD);
     if ($paymentMethodParameter != null) {
         $responseAvailability = PayUPayments::getPaymentMethodAvailability($paymentMethodParameter, $lang);
         $paymentMethod = $responseAvailability->paymentMethod;
         if (array_key_exists(PayUParameters::TOKEN_ID, $parameters)) {
             $requiredTokenId = array(PayUParameters::INSTALLMENTS_NUMBER, PayUParameters::TOKEN_ID);
             $required = array_merge($requiredAll, $requiredTokenId);
         } else {
             if (array_key_exists(PayUParameters::CREDIT_CARD_NUMBER, $parameters)) {
                 $requiredCreditCard = array(PayUParameters::INSTALLMENTS_NUMBER, PayUParameters::CREDIT_CARD_NUMBER, PayUParameters::PAYER_NAME, PayUParameters::CREDIT_CARD_EXPIRATION_DATE, PayUParameters::PAYMENT_METHOD);
                 $processWithoutCvv2 = PayUPayments::isProcessWithoutCvv2Param($parameters);
                 if (!$processWithoutCvv2) {
                     $requiredCreditCard[] = PayUParameters::CREDIT_CARD_SECURITY_CODE;
                 }
                 $required = array_merge($requiredAll, $requiredCreditCard);
             } else {
                 if ($paymentMethod != null && PayUPaymentMethodType::CASH == $paymentMethod->type) {
                     $requiredCash = array(PayUParameters::PAYER_NAME, PayUParameters::PAYER_DNI, PayUParameters::PAYMENT_METHOD);
                     $required = array_merge($requiredAll, $requiredCash);
                 } else {
                     if ("BOLETO_BANCARIO" == $paymentMethodParameter) {
                         $requiredBoletoBancario = array(PayUParameters::PAYER_NAME, PayUParameters::PAYER_DNI, PayUParameters::PAYMENT_METHOD, PayUParameters::PAYER_STREET, PayUParameters::PAYER_STREET_2, PayUParameters::PAYER_CITY, PayUParameters::PAYER_STATE, PayUParameters::PAYER_POSTAL_CODE);
                         $required = array_merge($requiredAll, $requiredBoletoBancario);
                     } else {
                         if ("PSE" == $paymentMethodParameter) {
                             $requiredPSE = array(PayUParameters::REFERENCE_CODE, PayUParameters::DESCRIPTION, PayUParameters::CURRENCY, PayUParameters::VALUE, PayUParameters::PAYMENT_METHOD, PayUParameters::PAYER_NAME, PayUParameters::PAYER_DOCUMENT_TYPE, PayUParameters::PAYER_DNI, PayUParameters::PAYER_EMAIL, PayUParameters::PAYER_CONTACT_PHONE, PayUParameters::PSE_FINANCIAL_INSTITUTION_CODE, PayUParameters::PAYER_PERSON_TYPE, PayUParameters::IP_ADDRESS, PayUParameters::PAYER_COOKIE, PayUParameters::USER_AGENT);
                             $required = array_merge($requiredAll, $requiredPSE);
                         } else {
                             if ($paymentMethod != null && $paymentMethod->type == PayUPaymentMethodType::CREDIT_CARD) {
                                 throw new InvalidArgumentException("Payment method credit card require at least one of two parameters [" . PayUParameters::CREDIT_CARD_NUMBER . '] or [' . PayUParameters::TOKEN_ID . ']');
                             } else {
                                 $required = $requiredAll;
                             }
                         }
                     }
                 }
             }
         }
     } else {
         throw new InvalidArgumentException(sprintf("The payment method value is invalid"));
     }
     CommonRequestUtil::validateParameters($parameters, $required);
     $request = RequestPaymentsUtil::buildPaymentRequest($parameters, $transactionType, $lang);
     $payUHttpRequestInfo = new PayUHttpRequestInfo(Environment::PAYMENTS_API, RequestMethod::POST);
     return PayUApiServiceUtil::sendRequest($request, $payUHttpRequestInfo);
 }