processCreditCardPayment($itemName, $payment, $user, $vendor); } else if ($payment['paymentMethod'] == Entity::PAYMENT_METHOD_CHECK) { return $this->processCheckPayment($itemName, $payment, $vendor); } throw new Exception('Unsupported payment method'); } private function processCreditCardPayment($itemName, array $payment, array $user, array $vendor) { $client = IpsFactory::create(); $options = Qs_Array::map($payment, ['ccNumber', 'ccExpirationDate', 'ccSecurityCode', 'amount' => 'total']); $options = array_merge($options, Qs_Array::map($user, ['firstName', 'lastName'])); $options = array_merge($options, $vendor['billingAddress']); $entity = new Entity($options); $entity->setDescription($itemName); $request = $entity->toIpsRequest(); return $client->sale($request); } private function processCheckPayment($invoiceNumber, array $payment, array $vendor) { $config = []; if (!empty($payment['merchantId'])) { $config['merchantId'] = $payment['merchantId']; } $client = SpsFactory::create($config); $options = Qs_Array::map($payment, [ 'checkType', 'routingNumber', 'accountNumber', 'amount' => 'total' ]); $options = array_merge($options, Qs_Array::map($vendor, ['phone', 'accountName' => 'businessName'])); $entity = new Entity($options); $entity->setDescription($invoiceNumber); $packet = $entity->toSpsPacket(); return $client->pay($packet); } /** * @param $payment * @return void */ protected function maskPaymentData(&$payment) { $view = Qs_View::getInstance(); if (!empty($payment['ccNumber'])) { $payment['ccNumber'] = $view->maskCreditCard($payment['ccNumber']); } if (!empty($payment['accountNumber'])) { $payment['accountNumber'] = $view->maskCheckAccountNumber($payment['accountNumber']); } } }