/** * Creates a customer with credit card information * @param parameters The parameters to be sent to the server * @param string $lang language of request see SupportedLanguages class * @return The response to the request sent * @throws PayUException * @throws InvalidArgumentException */ public static function createCustomerWithCreditCard($parameters, $lang = null) { PayUSubscriptionsRequestUtil::validateCustomer($parameters); PayUSubscriptionsRequestUtil::validateCreditCard($parameters); $customer = PayUSubscriptionsRequestUtil::buildCustomer($parameters); $creditCard = PayUSubscriptionsRequestUtil::buildCreditCard($parameters); $creditCards = array($creditCard); $customer->creditCards = $creditCards; $urlSegment = PayUSubscriptionsUrlResolver::getInstance()->getUrlSegment(PayUSubscriptionsUrlResolver::CUSTOMER_ENTITY, PayUSubscriptionsUrlResolver::ADD_OPERATION); $payUHttpRequestInfo = PayUSubscriptionsRequestUtil::buildHttpRequestInfo($urlSegment, $lang, RequestMethod::POST); return PayUApiServiceUtil::sendRequest($customer, $payUHttpRequestInfo); }
/** * Creates a credit card * @param parameters The parameters to be sent to the server * @param string $lang language of request see SupportedLanguages class * @return The response to the request sent * @throws PayUException * @throws InvalidArgumentException */ public static function create($parameters, $lang = null) { PayUSubscriptionsRequestUtil::validateCreditCard($parameters); $customerId = CommonRequestUtil::getParameter($parameters, PayUParameters::CUSTOMER_ID); if (!isset($customerId)) { throw new InvalidArgumentException(" The parameter customer id is mandatory "); } $request = PayUSubscriptionsRequestUtil::buildCreditCard($parameters); $urlSegment = PayUSubscriptionsUrlResolver::getInstance()->getUrlSegment(PayUSubscriptionsUrlResolver::CREDIT_CARD_ENTITY, PayUSubscriptionsUrlResolver::ADD_OPERATION, array($parameters[PayUParameters::CUSTOMER_ID])); $payUHttpRequestInfo = PayUSubscriptionsRequestUtil::buildHttpRequestInfo($urlSegment, $lang, RequestMethod::POST); return PayUApiServiceUtil::sendRequest($request, $payUHttpRequestInfo); }
/** * validate the Payment Method parameters. Only one payment methos is permitted * @param $parameters * @param $existParamBankAccount * @param $existParamCreditCard * @throws PayUException */ public static function validatePaymentMethod($parameters, $existParamBankAccount, $existParamCreditCard, $edit = FALSE) { if ($existParamBankAccount == TRUE && $existParamCreditCard == TRUE) { throw new PayUException(PayUErrorCodes::INVALID_PARAMETERS, "The subscription must have only one payment method"); } else { if ($existParamBankAccount == TRUE) { PayUSubscriptionsRequestUtil::validateBankAccount($parameters); if ($edit == FALSE) { //The TERMS_AND_CONDITIONS_ACEPTED Parameter is required for Bank Account $required = array(PayUParameters::TERMS_AND_CONDITIONS_ACEPTED); CommonRequestUtil::validateParameters($parameters, $required); } } else { if ($existParamCreditCard == TRUE) { PayUSubscriptionsRequestUtil::validateCreditCard($parameters); } else { throw new PayUException(PayUErrorCodes::INVALID_PARAMETERS, "The subscription must have one payment method"); } } } }