Esempio n. 1
0
 public function brand_creditcard_details()
 {
     $obj = new helpers();
     if (!$obj->checkBrandLogin()) {
         return redirect('brandLogin');
     }
     $country = DB::table('countries')->orderBy('name', 'ASC')->get();
     $alldata = array();
     foreach ($country as $key => $value) {
         $alldata[$value->country_id] = $value->name;
     }
     $brand_details = Brandmember::find(Session::get('brand_userid'));
     $brand_details->auth_payment_profile_id;
     $brand_details->auth_address_id;
     $allstates = array();
     if (Request::isMethod('post')) {
         $request = new AuthorizeNetCIM();
         $paymentProfile = new AuthorizeNetPaymentProfile();
         if ($brand_details->auth_profile_id == '') {
             $country = DB::table('countries')->where('country_id', '=', Request::input('card_country_id'))->first();
             $shipping_card_addr = array('card_holder_fname' => Request::input('card_holder_fname'), 'card_holder_lname' => Request::input('card_holder_lname'), 'expiry_month' => Request::input('expiry_month'), 'expiry_year' => Request::input('expiry_year'), 'cvv' => Request::input('cvv'), 'card_shiping_name' => Request::input('card_shiping_name'), 'card_shiping_address' => Request::input('card_shiping_address'), 'card_country_id' => Request::input('card_country_id'), 'card_shiping_city' => Request::input('card_shiping_city'), 'card_shipping_phone_no' => Request::input('card_shipping_phone_no'), 'card_state' => Request::input('card_state'), 'card_shipping_postcode' => Request::input('card_shipping_postcode'), 'email' => Request::input('email'), 'card_number' => Request::input('card_number'), 'country' => $country->name);
             $shipping_card_addr['company_name'] = Request::input('company_name');
             $shipping_card_addr['card_shipping_fax'] = Request::input('card_shipping_fax');
             $res = Authorizenet::createprofile($shipping_card_addr);
             if ($res['status'] == 'success') {
                 $brand = array('auth_profile_id' => $res['customer']['profile_id'], 'auth_payment_profile_id' => $res['customer']['payment_profile_id'], 'auth_address_id' => $res['customer']['address_id']);
                 $shipping_card_addr_serial = serialize($shipping_card_addr);
                 $brand['card_details'] = $shipping_card_addr_serial;
                 $brandresult = Brandmember::find(Session::get('brand_userid'));
                 $brandresult->update($brand);
                 Session::flash('success', 'Your credit card information is created successfully.');
                 return redirect('brand-creditcards');
             } else {
                 Session::flash('error', 'Something went wrong to update credit card.');
                 return redirect('brand-creditcards');
             }
         } else {
             if (strstr(Request::input('card_number'), 'XXXX') != false) {
                 $paymentProfile->payment->creditCard->cardNumber = Request::input('card_number');
             }
             $paymentProfile->payment->creditCard->expirationDate = Request::input('expiry_year') . "-" . Request::input('expiry_month');
             $response = $request->updateCustomerPaymentProfile($brand_details->auth_profile_id, $brand_details->auth_payment_profile_id, $paymentProfile);
             $address = new AuthorizeNetAddress();
             $address->firstName = Request::input('card_holder_fname');
             $address->lastName = Request::input('card_holder_lname');
             if (Request::input('company_name')) {
                 $address->company = Request::input('company_name');
             }
             //  if(strstr(Request::input('card_number'),'XXXX')!=false)
             //$address->card_number = Request::input('card_number');
             $address->address = Request::input('card_shiping_address');
             $address->city = Request::input('card_shiping_city');
             $address->state = $obj->get_state(Request::input('card_state'));
             $address->zip = Request::input('card_shipping_postcode');
             $country = DB::table('countries')->where('country_id', '=', Request::input('card_country_id'))->first();
             $address->country = $country->name;
             $address->phoneNumber = Request::input('card_shipping_phone_no');
             if (Request::input('card_shipping_fax')) {
                 $address->faxNumber = Request::input('card_shipping_fax');
             }
             // print_r($address);
             // exit;
             $response2 = $request->updateCustomerShippingAddress($brand_details->auth_profile_id, $brand_details->auth_address_id, $address);
             if ($response->isOk() && $response2->isOk()) {
                 $shipping_card_addr = array('card_holder_fname' => Request::input('card_holder_fname'), 'card_holder_lname' => Request::input('card_holder_lname'), 'expiry_month' => Request::input('expiry_month'), 'expiry_year' => Request::input('expiry_year'), 'card_shiping_address' => Request::input('card_shiping_address'), 'card_country_id' => Request::input('card_country_id'), 'card_shiping_city' => Request::input('card_shiping_city'), 'card_shipping_phone_no' => Request::input('card_shipping_phone_no'), 'card_state' => Request::input('card_state'), 'card_shipping_postcode' => Request::input('card_shipping_postcode'));
                 $shipping_card_addr_serial = serialize($shipping_card_addr);
                 $brand['card_details'] = $shipping_card_addr_serial;
                 $brandresult = Brandmember::find(Session::get('brand_userid'));
                 $brandresult->update($brand);
                 Session::flash('success', 'Your credit card information is updated successfully.');
                 return redirect('brand-creditcards');
             } else {
                 Session::flash('error', 'Something went wrong to update credit card.');
                 return redirect('brand-creditcards');
             }
         }
     }
     $request = new AuthorizeNetCIM();
     $creditcard = $request->getCustomerProfile($brand_details->auth_profile_id);
     if (isset($creditcard->xml->profile)) {
         $carddetails['profile_id'] = $creditcard->xml->profile->customerProfileId;
         $carddetails['first_name'] = $creditcard->xml->profile->shipToList->firstName;
         $carddetails['last_name'] = $creditcard->xml->profile->shipToList->lastName;
         $carddetails['card_number'] = $creditcard->xml->profile->paymentProfiles->payment->creditCard->cardNumber;
         $cc = unserialize($brand_details->card_details);
         $carddetails['expiry_month'] = $cc['expiry_month'];
         $carddetails['expiry_year'] = $cc['expiry_year'];
         $carddetails['company_name'] = $creditcard->xml->profile->shipToList->company;
         $carddetails['card_shiping_address'] = $creditcard->xml->profile->shipToList->address;
         $carddetails['card_country_id'] = $cc['card_country_id'];
         $carddetails['card_state'] = $cc['card_state'];
         $carddetails['card_shiping_city'] = $creditcard->xml->profile->shipToList->city;
         $carddetails['card_shipping_postcode'] = $creditcard->xml->profile->shipToList->zip;
         $carddetails['card_shipping_phone_no'] = $creditcard->xml->profile->shipToList->phoneNumber;
         $carddetails['card_shipping_fax'] = $creditcard->xml->profile->shipToList->faxNumber;
         $states = DB::table('zones')->where('country_id', $carddetails['card_country_id'])->orderBy('name', 'ASC')->get();
         $allstates = array();
         foreach ($states as $key => $value) {
             $allstates[$value->zone_id] = $value->name;
         }
     } else {
         $carddetails['profile_id'] = '';
         $carddetails['first_name'] = '';
         $carddetails['last_name'] = '';
         $carddetails['card_number'] = '';
         $carddetails['expiry_month'] = '';
         $carddetails['expiry_year'] = '';
         $carddetails['company_name'] = '';
         $carddetails['card_shiping_address'] = '';
         $carddetails['card_country_id'] = '';
         $carddetails['card_state'] = '';
         $carddetails['card_shiping_city'] = '';
         $carddetails['card_shipping_postcode'] = '';
         $carddetails['card_shipping_phone_no'] = '';
         $carddetails['card_shipping_fax'] = '';
     }
     return view('frontend.brand.brand_creditcard', compact('brand_details', 'alldata', 'allstates', 'carddetails'), array('title' => 'Creditcard Information'));
 }