コード例 #1
0
 public function postUpdateCard()
 {
     // Add Curl library
     require_once app_path() . "/libraries/Curl/Curl.php";
     // Get Product
     $product = Product::where('code', Input::get('code'))->first();
     // Get Expiry month and year
     $expiry = explode(' / ', Input::get('ccExpire'));
     // Put all values in session
     Session::flash('ccNum', Input::get('ccNum'));
     Session::flash('ccExpire', Input::get('ccExpire'));
     Session::flash('ccCVC', Input::get('ccCVC'));
     $data = array('email' => Input::get('email'), 'code' => Input::get('code'), 'number' => Input::get('ccNum'), 'exp_month' => !empty($expiry[0]) ? $expiry[0] : NULL, 'exp_year' => !empty($expiry[1]) ? $expiry[1] : NULL, 'cvc' => Input::get('ccCVC'));
     $data['key'] = DKHelpers::GenerateHash($data, $product->api_key);
     $url = url() . "/api/v1/update-card";
     // Post data to IPN
     $curl = new Curl();
     $response = $curl->simple_post($url, $data, array(CURLOPT_BUFFERSIZE => 10));
     $response = json_decode($response);
     if (empty($response->error)) {
         $success = "Your card (**** **** **** {$response->last4}) has been updated successfully.";
         return Redirect::back()->with('success', $success);
     } else {
         return Redirect::back()->with('error', $response->error);
     }
 }
コード例 #2
0
 public function getPayload()
 {
     $code = Input::get('code');
     $api_key = Input::get('api_key');
     $license_key = Input::get('license');
     $activate = Input::get('activate');
     $current_url = url("admin/licenses/payload?code={$code}&api_key={$api_key}&license={$license_key}");
     // Page Title
     $this->_data['page_title'] = "Licenses - Get Payload";
     $this->_data['license_key'] = $license_key;
     $this->_data['uses'] = LicensesUses::getAllUsage($license_key);
     // Include libraries
     require_once app_path() . "/libraries/Curl/Curl.php";
     $params = array("code" => $code, "license" => $license_key);
     $curl = new Curl();
     if ($activate) {
         $params['guid'] = time();
     }
     $params['key'] = DKHelpers::GenerateHash($params, $api_key);
     if ($activate) {
         $response = $curl->simple_post(url('api/v1/license-manager/activate'), $params, array(CURLOPT_BUFFERSIZE => 10));
         $response = json_decode($response);
         if (isset($response->success) and $response->success == 'false') {
             if (isset($response->overusage) and $response->overusage == 'true') {
                 Session::flash('alert_error', '<strong>Alert!</strong> License cannot be activated due to overusage.');
                 return Redirect::to($current_url);
             }
         } else {
             Session::flash('alert_message', '<strong>Done!</strong> License has been activated successfully.');
             return Redirect::to($current_url);
         }
     }
     // Get Payload
     $this->_data['payload'] = $curl->simple_post(url('api/v1/license-manager'), $params, array(CURLOPT_BUFFERSIZE => 10));
     $this->_data['activate_url'] = $current_url . '&activate=true';
     return View::make('admin.licenses.payload', $this->_data)->nest('header', 'admin.common.header', $this->_data)->nest('footer', 'admin.common.footer', $this->_data);
 }
コード例 #3
0
 /**
  * Complete refund and push notification
  */
 static function completeRefund($transaction)
 {
     // Update transaction
     $transaction->is_refunded = 1;
     $transaction->save();
     // Push to IPN
     $ipn_data = array("type" => "refund", "plan" => $transaction->plan->code, "email" => $transaction->purchase->buyer->email);
     // Add Curl library
     require_once app_path() . "/libraries/Curl/Curl.php";
     // Add an encrypted key to the request
     $ipn_data['key'] = DKHelpers::GenerateHash($ipn_data, $transaction->purchase->product->api_key);
     // Post data to IPN
     $curl = new Curl();
     $curl->simple_post($transaction->purchase->product->ipn_url, $ipn_data, array(CURLOPT_BUFFERSIZE => 10));
     // Send refund email to buyer
     self::send_email_refund($transaction->purchase->product->name, $transaction->plan->name, $transaction->purchase->buyer->email, $transaction->pay_id, $transaction->amount);
     return TRUE;
 }
コード例 #4
0
 /**
  * Generate Hash for a request
  */
 private function _generateHash($params, $secret_key)
 {
     return DKHelpers::GenerateHash($params, $secret_key);
 }
コード例 #5
0
 /**
  * Cancel Subscription
  */
 public function getCancelSubscription($id, $at_period_end = FALSE)
 {
     // Page Title
     $this->_data['page_title'] = "Cancel Subscription";
     $transaction = Transaction::find($id);
     $this->_data['transaction'] = $transaction;
     $pay_id = $transaction->pay_id;
     $pay_method = DKHelpers::GetPayMethod($pay_id);
     // If Stripe
     if ($pay_method == 'Stripe') {
         $plan_id = $transaction->plan->stripe_id;
         $stripe_sub_id = NULL;
         $is_stripe_sub_active = 0;
         // Add Stripe library
         require_once app_path() . "/libraries/stripe-php-1.9.0/lib/Stripe.php";
         // Add Stripe library
         Stripe::setApiKey(Config::get('project.stripe_secret_key'));
         try {
             $ch = Stripe_Charge::retrieve($pay_id);
             $subscriptions = Stripe_Customer::retrieve($ch->customer)->subscriptions->all(array('count' => 100));
             foreach ($subscriptions->data as $subscription) {
                 if ($subscription->plan->id == $plan_id) {
                     $stripe_sub_id = $subscription->id;
                     if ($subscription->status == 'active') {
                         $is_stripe_sub_active = 1;
                     }
                     break;
                 }
             }
             $this->_data['stripe_customer_id'] = $ch->customer;
         } catch (Exception $e) {
             Session::flash('alert_error', '<strong>Ooops!</strong> Subscription was not retreived, try again.');
             return Redirect::to("admin/transactions/detail/{$transaction->id}");
         }
     }
     // If PayPal
     if ($pay_method == 'PayPal') {
         $paypal_sub_id = NULL;
         $is_paypal_sub_active = 0;
         $purchase = $transaction->purchase;
         $paypal_sub_id = $purchase->paypal_sub_id;
         $config = array('mode' => Config::get('project.paypal_mode'), 'acct1.UserName' => Config::get('project.paypal_api_username'), 'acct1.Password' => Config::get('project.paypal_api_password'), 'acct1.Signature' => Config::get('project.paypal_api_signature'));
         /*
          * Obtain information about a recurring payments profile. 
          */
         $getRPPDetailsReqest = new GetRecurringPaymentsProfileDetailsRequestType();
         /*
          * (Required) Recurring payments profile ID returned in the CreateRecurringPaymentsProfile response. 19-character profile IDs are supported for compatibility with previous versions of the PayPal API.
          */
         $getRPPDetailsReqest->ProfileID = $paypal_sub_id;
         $getRPPDetailsReq = new GetRecurringPaymentsProfileDetailsReq();
         $getRPPDetailsReq->GetRecurringPaymentsProfileDetailsRequest = $getRPPDetailsReqest;
         /*
          * 	 ## Creating service wrapper object
         Creating service wrapper object to make API call and loading
         Configuration::getAcctAndConfig() returns array that contains credential and config parameters
         */
         $paypalService = new PayPalAPIInterfaceServiceService($config);
         try {
             /* wrap API method calls on the service object with a try catch */
             $getRPPDetailsResponse = $paypalService->GetRecurringPaymentsProfileDetails($getRPPDetailsReq);
         } catch (Exception $ex) {
             Session::flash('alert_error', '<strong>Ooops!</strong> Subscription was not retreived, try again.');
             return Redirect::to("admin/transactions/detail/{$transaction->id}");
         }
         if (isset($getRPPDetailsResponse) and $getRPPDetailsResponse->Ack == 'Success') {
             $status = $getRPPDetailsResponse->GetRecurringPaymentsProfileDetailsResponseDetails->ProfileStatus;
             if ($status == 'ActiveProfile') {
                 $is_paypal_sub_active = 1;
             }
         }
         //exit;
     }
     $this->_data['subscription_id'] = $pay_method == 'Stripe' ? $stripe_sub_id : $paypal_sub_id;
     $this->_data['is_sub_active'] = $pay_method == 'Stripe' ? $is_stripe_sub_active : $is_paypal_sub_active;
     $this->_data['at_period_end'] = $at_period_end;
     $this->_data['pay_method'] = $pay_method;
     return View::make('admin.transactions.cancel-subscription', $this->_data)->nest('header', 'admin.common.header', $this->_data)->nest('footer', 'admin.common.footer', $this->_data);
 }