public function index() { $all_brand_member = DB::table('brandmembers')->where('role', 1)->where('status', 1)->where('admin_status', 1)->get(); foreach ($all_brand_member as $brand) { //echo $brand->fname; $subscription = DB::table('subscription_history')->where('payment_status', 'pending')->where('member_id', $brand->id)->first(); if (count($subscription) <= 0) { $end_date = date("Y-m-d", strtotime($brand->created_at . ' + 30 days')); $setting = DB::table('sitesettings')->where('name', 'brand_fee')->first(); $subdata = array("member_id" => $brand->id, "start_date" => $brand->created_at, "end_date" => $end_date, "subscription_fee" => $setting->value); Subscription::create($subdata); } else { $paidsubscription = DB::table('subscription_history')->where('payment_status', 'paid')->where('member_id', $brand->id)->orderBy('end_date', 'DESC')->first(); if (is_object($paidsubscription) && $paidsubscription->end_date <= date("Y-m-d")) { echo 'subid-' . $paidsubscription->subscription_id . '- paid in prev month <br />'; } else { $today = Date('Y-m-d'); $enddate = date("Y-m-d", strtotime($subscription->end_date . " + 1 day")); if ($enddate == $today) { //charge here if (empty($brand->auth_profile_id)) { continue; } echo "will be charged " . $subscription->subscription_id . '<br />'; // Create Auth & Capture Transaction $request = new AuthorizeNetCIM(); $transaction = new AuthorizeNetTransaction(); $transaction->amount = $subscription->subscription_fee; $transaction->customerProfileId = $brand->auth_profile_id; $transaction->customerPaymentProfileId = $brand->auth_payment_profile_id; $transaction->customerShippingAddressId = $brand->auth_address_id; $lineItem = new AuthorizeNetLineItem(); $lineItem->itemId = $subscription->subscription_id; $lineItem->name = $brand->fname; $lineItem->description = $brand->fname . " charged for subscription of " . $subscription->start_date; $lineItem->quantity = "1"; $lineItem->unitPrice = $subscription->subscription_fee; $lineItem->taxable = "false"; $transaction->lineItems[] = $lineItem; $response = $request->createCustomerProfileTransaction("AuthCapture", $transaction); if ($response->isOk()) { $transactionResponse = $response->getTransactionResponse(); $transactionId = $transactionResponse->transaction_id; $subdata = array("transaction_id" => $transactionResponse->transaction_id, "payment_status" => 'paid'); $sub = DB::table('subscription_history')->where('subscription_id', $subscription->subscription_id)->update($subdata); } } } } } }
public function index() { $all_brand_member = DB::table('brandmembers')->where('role', 1)->where('status', 1)->where('admin_status', 1)->get(); DB::connection()->enableQueryLog(); foreach ($all_brand_member as $brand) { $product = DB::table('products')->select(DB::raw('products.id,products.brandmember_id,products.product_name,products.product_slug,products.image1, MIN(`actual_price`) as `min_price`,MAX(`actual_price`) as `max_price`'))->leftJoin('product_formfactors', 'products.id', '=', 'product_formfactors.product_id')->where('products.brandmember_id', '=', $brand->id)->where('products.active', 1)->where('products.is_deleted', 0)->where('product_formfactors.servings', '!=', 0)->where('products.discountinue', 0)->groupBy('product_formfactors.product_id'); $profile = MemberProfile::find($brand->id); if (isset($profile) && $profile->count) { $count = (int) $profile->count; } else { $count = 0; } $setting = DB::table('sitesettings')->where('name', 'brand_fee')->first(); $setting2 = DB::table('sitesettings')->where('name', 'brand_perproduct_fee')->first(); if ($count == 1) { $fee = $setting->value; } elseif ($count > 1) { $fee = $setting->value; $perproduct_fee = $setting2->value; $fee = $fee + $perproduct_fee * $count; } else { $fee = 0; } //echo $brand->id; //echo '<br />'; $br = array('member_fee' => $fee); //print_r($br); DB::table('brandmembers')->where('id', $brand->id)->update(array('member_fee' => $fee)); } foreach ($all_brand_member as $brand) { //echo $brand->fname; $subscription = DB::table('subscription_history')->where('payment_status', 'pending')->where('member_id', $brand->id)->first(); if (count($subscription) <= 0) { $paidsub = DB::table('subscription_history')->where('payment_status', 'paid')->where('member_id', $brand->id)->orderBy('end_date', 'DESC')->first(); if (count($paidsub) > 0) { $start_date = $paidsub->end_date; $end_date = date("Y-m-d", strtotime($start_date . ' + 30 days')); } else { $start_date = $brand->created_at; $end_date = date("Y-m-d", strtotime($start_date . ' + 30 days')); } $setting = DB::table('sitesettings')->where('name', 'brand_fee')->first(); $subdata = array("member_id" => $brand->id, "start_date" => $start_date, "end_date" => $end_date, "subscription_fee" => $brand->member_fee); Subscription::create($subdata); } else { $paidsubscription = DB::table('subscription_history')->where('member_id', $brand->id)->orderBy('end_date', 'DESC')->first(); if (is_object($paidsubscription) && $paidsubscription->end_date <= date("Y-m-d") && $paidsubscription->payment_status == 'paid') { echo 'subid-' . $paidsubscription->subscription_id . '- paid in prev month <br />'; } else { $today = Date('Y-m-d'); $enddate = date("Y-m-d", strtotime($subscription->end_date . " + 1 day")); if ($enddate <= $today) { //charge here if (empty($brand->auth_profile_id)) { continue; } echo "will be charged " . $subscription->member_id . '<br />'; // Create Auth & Capture Transaction $request = new AuthorizeNetCIM(); $transaction = new AuthorizeNetTransaction(); $transaction->amount = $brand->member_fee; $transaction->customerProfileId = $brand->auth_profile_id; $transaction->customerPaymentProfileId = $brand->auth_payment_profile_id; $transaction->customerShippingAddressId = $brand->auth_address_id; $lineItem = new AuthorizeNetLineItem(); $lineItem->itemId = $subscription->subscription_id; $lineItem->name = $brand->fname; $lineItem->description = $brand->fname . " charged for subscription of " . $subscription->start_date; $lineItem->quantity = "1"; $lineItem->unitPrice = $brand->member_fee; $lineItem->taxable = "false"; $transaction->lineItems[] = $lineItem; $response = $request->createCustomerProfileTransaction("AuthCapture", $transaction); $updateWithCode = DB::table('brandmembers')->where('id', '=', $subscription->member_id)->update(array('subscription_status' => 'expired')); if ($response->isOk()) { $transactionResponse = $response->getTransactionResponse(); $transactionId = $transactionResponse->transaction_id; $subdata = array("transaction_id" => $transactionResponse->transaction_id, "payment_status" => 'paid'); $sub = DB::table('subscription_history')->where('subscription_id', $subscription->subscription_id)->update($subdata); $updateWithCode = DB::table('brandmembers')->where('id', '=', $subscription->member_id)->update(array('subscription_status' => 'active')); } else { print_r($response); } } } } } $this->onlineusers(); }
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')); }
public function createprofile($card) { //require_once( __DIR__ . DIRECTORY_SEPARATOR .'auth/shared/AuthorizeNetTypes.php'); //require_once( __DIR__ . DIRECTORY_SEPARATOR .'auth/shared/AuthorizeNetXMLResponse.php'); //require_once( __DIR__ . DIRECTORY_SEPARATOR .'auth/shared/AuthorizeNetRequest.php'); //require_once( __DIR__ . DIRECTORY_SEPARATOR .'auth/AuthorizeNetCIM.php'); //require_once( __DIR__ . DIRECTORY_SEPARATOR .'auth/shared/AuthorizeNetResponse.php'); //require_once( __DIR__ . DIRECTORY_SEPARATOR .'auth/AuthorizeNetAIM.php'); // $request = new AuthorizeNetCIM(); $customerProfile = new AuthorizeNetCustomer(); $customerProfile->description = $card['card_holder_fname'] . " " . $card['card_holder_lname']; $customerProfile->merchantCustomerId = time() . rand(1, 100); $customerProfile->email = $card['email']; $response = $request->createCustomerProfile($customerProfile); $customerProfileId = $response->getCustomerProfileId(); $customer = array(); if ($customerProfileId) { $customer['profile_id'] = $customerProfileId; } // Update customer profile // $customerProfile->description = "I am Ujjal"; //$customerProfile->email = "*****@*****.**"; // $response = $request->updateCustomerProfile($customerProfileId, $customerProfile); if ($customerProfileId) { // Add payment profile. $paymentProfile = new AuthorizeNetPaymentProfile(); $paymentProfile->customerType = "individual"; $paymentProfile->payment->creditCard->cardNumber = $card['card_number']; $paymentProfile->payment->creditCard->expirationDate = $card['expiry_year'] . "-" . $card['expiry_month']; $response = $request->createCustomerPaymentProfile($customerProfileId, $paymentProfile); // print_r( $response->xml->messages->message->text); $paymentProfileId = $response->getPaymentProfileId(); if ($paymentProfileId) { $customer['payment_profile_id'] = $paymentProfileId; } // Add shipping address. $address = new AuthorizeNetAddress(); $address->firstName = $card['card_holder_fname']; $address->lastName = $card['card_holder_lname']; if ($card['company_name']) { $address->company = $card['company_name']; } $address->address = $card['card_shiping_address']; $address->city = $card['card_shiping_city']; $address->state = $card['card_state']; $address->zip = $card['card_shipping_postcode']; $address->country = $card['country']; $address->phoneNumber = $card['card_shipping_phone_no']; if ($card['card_shipping_fax']) { $address->faxNumber = $card['card_shipping_fax']; } $response = $request->createCustomerShippingAddress($customerProfileId, $address); if ($response->isOk()) { $customerAddressId = $response->getCustomerAddressId(); $customer['address_id'] = $customerAddressId; } } // Update payment profile. //$paymentProfile->payment->creditCard->cardNumber = "4111111111111111"; //$paymentProfile->payment->creditCard->expirationDate = "2017-11"; //$response = $request->updateCustomerPaymentProfile($customerProfileId,$paymentProfileId, $paymentProfile); if ($customerProfileId && $paymentProfileId) { $result = array('customer' => $customer); $result['status'] = 'success'; } else { $result['status'] = 'fail'; $result['message'] = (string) $response->xml->messages->message->text; } return $result; }