/** * @param $apiMethod * @param $customer * * @return ResponseInterface */ private function _createCustomer($apiMethod, $customer) { /** @var Customer $customer */ $customer = ClassValidator::getInstance('Eway\\Rapid\\Model\\Customer', $customer); $apiMethod = EnumValidator::validate('Eway\\Rapid\\Enum\\ApiMethod', 'ApiMethod', $apiMethod); $transaction = ['Customer' => $customer->toArray(), 'Method' => PaymentMethod::CREATE_TOKEN_CUSTOMER, 'TransactionType' => TransactionType::PURCHASE]; if (isset($customer->RedirectUrl)) { $transaction['RedirectUrl'] = $customer->RedirectUrl; } if (isset($customer->CancelUrl)) { $transaction['CancelUrl'] = $customer->CancelUrl; } /** @var Transaction $transaction */ $transaction = ClassValidator::getInstance('Eway\\Rapid\\Model\\Transaction', $transaction); switch ($apiMethod) { case ApiMethod::DIRECT: return $this->getHttpService()->postTransaction($transaction->toArray()); case ApiMethod::RESPONSIVE_SHARED: $transaction->Payment = ['TotalAmount' => 0]; return $this->getHttpService()->postAccessCodeShared($transaction->toArray()); case ApiMethod::TRANSPARENT_REDIRECT: $transaction->Payment = ['TotalAmount' => 0]; return $this->getHttpService()->postAccessCode($transaction->toArray()); default: // Although right now this code is not reachable, protect against incomplete // changes to ApiMethod throw new MethodNotImplementedException(); } }
/** * @param string $class * @param string $field * @param mixed $value */ protected function validateEnum($class, $field, $value) { $this->attributes[$field] = EnumValidator::validate($class, $field, $value); }
/** * * @param $apiMethod * @param type $customer * @return ResponseInterface * @throws MethodNotImplementedException */ private function doUpdateCustomer($apiMethod, $customer) { /** @var Customer $customer */ $customer = ClassValidator::getInstance('Eway\\Rapid\\Model\\Customer', $customer); $apiMethod = EnumValidator::validate('Eway\\Rapid\\Enum\\ApiMethod', 'ApiMethod', $apiMethod); $transaction = $this->customerToTransaction($customer); $transaction->Method = PaymentMethod::UPDATE_TOKEN_CUSTOMER; $transaction->Payment = ['TotalAmount' => 0]; switch ($apiMethod) { case ApiMethod::DIRECT: return $this->getHttpService()->postTransaction($transaction->toArray()); case ApiMethod::RESPONSIVE_SHARED: return $this->getHttpService()->postAccessCodeShared($transaction->toArray()); case ApiMethod::TRANSPARENT_REDIRECT: return $this->getHttpService()->postAccessCode($transaction->toArray()); default: // Although right now this code is not reachable, protect against incomplete // changes to ApiMethod throw new MethodNotImplementedException(); } }