public function paymentProfilesEdit($gatewayProfileId = null)
 {
     if (!empty($this->request->data)) {
         //pr($this->request->data);
         $data = $this->request->data;
         if ($data['DrexCartAddress']['billing_zip'] && $data['DrexCartGatewayProfile']['account_number'] && $data['DrexCartGatewayProfile']['expiration'] && $data['DrexCartGatewayProfile']['code']) {
             // try to save card
             $this->DrexCartGateway = ClassRegistry::init('DrexCart.DrexCartGateway');
             $this->DrexCartGateway->create();
             $gateway = $this->DrexCartGateway->find('first', array('conditions' => array('type' => 'authorize')));
             $user = $this->userManager->getUserData();
             $payment = new AuthorizePaymentModule($gateway['DrexCartGateway']['id'], $gateway['DrexCartGateway']['wsdl_url'], $gateway['DrexCartGateway']['api_login'], $gateway['DrexCartGateway']['api_key']);
             $userProfileId = $payment->createCustomer($user['DrexCartUser']);
             $data['DrexCartGatewayProfile']['expiration'] = $data['DrexCartGatewayProfile']['expiration']['year'] . '-' . $data['DrexCartGatewayProfile']['expiration']['month'];
             $paymentProfileId = $payment->addCard($userProfileId, $data['DrexCartGatewayProfile'], $data['DrexCartAddress']);
             if ($paymentProfileId) {
                 //$this->Session->setFlash('Card added successfully!', 'default', array('class'=>'alert alert-success'));
                 $this->set('updated', true);
             } else {
                 $this->set('errors', $payment->errors);
             }
         }
     }
     $this->set('gatewayProfileId', $gatewayProfileId);
 }
Ejemplo n.º 2
0
 public function createOrderPayment($user = null, $orderInfo = null)
 {
     $total = $this->getCheckoutTotal();
     // figure out what payment method was used
     $paymentInfo = CakeSession::read('DrexCartGatewayProfile');
     if (isset($paymentInfo['id']) && is_numeric($paymentInfo['id'])) {
         // already have a payment profile
         $this->DrexCartGatewayProfile = ClassRegistry::init('DrexCart.DrexCartGatewayProfile');
         $this->DrexCartGatewayProfile->create();
         $gwCard = $this->DrexCartGatewayProfile->find('first', array('fields' => array('DrexCartGatewayProfile.*', 'DrexCartGatewayUser.*'), 'joins' => array(array('table' => 'drex_cart_gateway_users', 'alias' => 'DrexCartGatewayUser', 'type' => 'left', 'conditions' => array('DrexCartGatewayUser.id=DrexCartGatewayProfile.drex_cart_gateway_users_id'))), 'conditions' => array('DrexCartGatewayProfile.id' => $paymentInfo['id'], 'DrexCartGatewayUser.drex_cart_users_id' => $user['id'])));
         if ($gwCard) {
             $this->DrexCartGateway = ClassRegistry::init('DrexCart.DrexCartGateway');
             $this->DrexCartGateway->create();
             $gateway = $this->DrexCartGateway->getGatewayById($gwCard['DrexCartGatewayUser']['drex_cart_gateways_id']);
             if ($gateway) {
                 if ($gateway['DrexCartGateway']['type'] == 'authorize') {
                     // authorize.net for credit cards
                     $paymentModule = new AuthorizePaymentModule($gateway['DrexCartGateway']['id'], $gateway['DrexCartGateway']['wsdl_url'], $gateway['DrexCartGateway']['api_login'], $gateway['DrexCartGateway']['api_key']);
                 } else {
                     if ($gateway['DrexCartGateway']['type'] == 'paypal') {
                         // paypal
                     }
                 }
             }
             $transactionId = $paymentModule->authorizePayment($gwCard['DrexCartGatewayUser']['profile_id'], $gwCard['DrexCartGatewayProfile']['profile_id'], $total);
             return $transactionId;
         } else {
             throw new Exception('Payment profile does not exist!');
         }
     } else {
         // check for user gateway profile
         $gatewayId = $paymentInfo['drex_cart_gateways_id'];
         $this->DrexCartGateway = ClassRegistry::init('DrexCart.DrexCartGateway');
         $this->DrexCartGateway->create();
         $this->DrexCartGatewayUser = ClassRegistry::init('DrexCart.DrexCartGatewayUser');
         $this->DrexCartGatewayUser->create();
         $gateway = $this->DrexCartGateway->getGatewayById($gatewayId);
         if ($gateway) {
             if ($gateway['DrexCartGateway']['type'] == 'authorize') {
                 // authorize.net for credit cards
                 $paymentModule = new AuthorizePaymentModule($gatewayId, $gateway['DrexCartGateway']['wsdl_url'], $gateway['DrexCartGateway']['api_login'], $gateway['DrexCartGateway']['api_key']);
             } else {
                 if ($gateway['DrexCartGateway']['type'] == 'paypal') {
                     // paypal
                 }
             }
         }
         if ($gwUser = $this->DrexCartGatewayUser->find('first', array('conditions' => array('drex_cart_users_id' => $user['id'], 'drex_cart_gateways_id' => $gatewayId)))) {
             // gateway user account profile exists
             $userProfileId = $gwUser['DrexCartGatewayUser']['profile_id'];
         } else {
             if ($userProfileId = $paymentModule->createCustomer($user)) {
                 //echo 'userProfileId: '.$userProfileId;
             } else {
                 $errorMessage = '';
                 foreach ($paymentModule->errors as $error) {
                     $errorMessage .= $error . '<br />';
                 }
                 throw new Exception($errorMessage);
             }
         }
         if ($userCardProfileId = $paymentModule->addCard($userProfileId, $paymentInfo, $orderInfo)) {
             //echo '<br /> userCartProfileId: '.$userCardProfileId;
         } else {
             $errorMessage = '';
             foreach ($paymentModule->errors as $error) {
                 $errorMessage .= $error . '<br />';
             }
             throw new Exception($errorMessage);
         }
         //exit;
         $transactionId = $paymentModule->authorizePayment($userProfileId, $userCardProfileId, $total);
         return $transactionId;
     }
     /*
     	$soap->CreateCustomerProfile(new CreateCustomerPaymentProfile(new MerchantAuthenticationType('9eFfhH98Uz', '38UAqh26T7U3gc4y'),
     			null,
     			new CustomerPaymentProfileType(new PaymentType($bankAccount, $creditCard),
     					$driversLicense,
     					$taxId),
     			$validationMode));
     */
 }