Example #1
0
function webservice_post($url, $params, $jsonRequest = FALSE)
{
    // Parse the RequestMethod out of the request for debugging purposes
    if (isset($params['RequestMethod'])) {
        $requestMethod = $params['RequestMethod'];
    } else {
        $requestMethod = '';
    }
    if (empty($url)) {
        log_message('error', "Canceling {$requestMethod} POST to an empty URL");
        return array('Message' => 'Web service URL is not configured');
    }
    if ($jsonRequest) {
        $params = json_encode($params);
    }
    // POST our query and fetch the response
    $curl = new Curl();
    $response = $curl->simple_post($url, $params);
    //log_message('debug', sprintf('Response received from %s POST to %s: %s', $requestMethod, $url, $response));
    // JSON decode the response
    $response = json_decode($response, TRUE);
    if (!isset($response)) {
        $response = array('Message' => 'Invalid or missing response');
    }
    return $response;
}
 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);
     }
 }
Example #3
0
 /**
  * Sends statistics back to pyrocms.com
  *
  * These are only used to see which OS's we should develop for and are anonymous.
  *
  * @author jeroenvdgulik
  * @since 1.0.1
  */
 public function statistics()
 {
     $this->load->library('installer_lib');
     $this->installer_lib->mysql_acceptable('server');
     $this->installer_lib->mysql_acceptable('client');
     $this->installer_lib->gd_acceptable();
     $data = array('version' => CMS_VERSION, 'php_version' => phpversion(), 'webserver_hash' => md5($this->session->userdata('http_server') . $this->input->server('SERVER_NAME') . $this->input->server('SERVER_ADDR') . $this->input->server('SERVER_SIGNATURE')), 'webserver_software' => $this->input->server('SERVER_SOFTWARE'), 'dbserver' => $this->installer_lib->mysql_server_version, 'dbclient' => $this->installer_lib->mysql_client_version, 'gd_version' => $this->installer_lib->gd_version, 'zlib_version' => $this->installer_lib->zlib_enabled(), 'curl' => $this->installer_lib->curl_enabled());
     include '../system/sparks/curl/1.2.1/libraries/Curl.php';
     $url = 'https://www.pyrocms.com/statistics/add';
     $curl = new Curl();
     $curl->simple_post($url, $data);
 }
function update_appearance($userID, $appearance)
{
    $config =& get_config();
    $url = $config['user_service'];
    $params = array('RequestMethod' => 'AddUserData', 'UserID' => $userID, 'LLPackedAppearance' => json_encode($appearance));
    $curl = new Curl();
    $response = json_decode($curl->simple_post($url, $params), TRUE);
    if (!isset($response)) {
        log_message('error', "Update appearance call to {$url} failed");
        $response = array('Message' => 'Invalid or missing response');
    }
    return $response;
}
 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);
 }
/**
 * @author Philip Sturgeon
 * @created 9 Dec 2008
 */
function webservice_post($url, $params, $jsonRequest = FALSE)
{
    if (empty($url)) {
        log_message('error', 'Canceling web service POST to an empty URL');
        return array('Message' => 'Web service address is not configured');
    }
    if ($jsonRequest) {
        $params = json_encode($params);
    }
    $curl = new Curl();
    $response = $curl->simple_post($url, $params);
    $jsonResponse = json_decode($response, TRUE);
    if (empty($jsonResponse)) {
        log_message('error', "Invalid or missing response from {$url}");
        $jsonResponse = array('Message' => 'Invalid or missing response: ' . $response);
    }
    return $jsonResponse;
}
Example #7
0
 /**
  * Curl data
  *
  * @return void
  * @author apple
  **/
 function curlData($url, $params = array(), $type = 'GET', $debug = 0, $options = array())
 {
     $cl = new Curl();
     if ($type == 'GET') {
         $params = $params ? '?' . MY_paraseGetArray($params) : "";
         $curl['url'] = site_url($url . $params);
         $json = $cl->simple_get($curl['url'], $options);
     } else {
         $curl['url'] = site_url($url);
         $json = $cl->simple_post($curl['url'], $params, $options);
     }
     if ($debug) {
         $cl->debug();
     }
     // debug
     $json = json_decode($json, TRUE);
     return $json;
 }
 /**
  * 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;
 }
Example #9
0
	/**
	 * Sends statistics back to pyrocms.com. These are only used to see which OS's we should develop for
	 * and are anonymous.
	 *
	 * @access	public
	 * @author	jeroenvdgulik
	 * @since	1.0.0.0
	 * @return	void
	 */
	public function statistics()
	{
		$this->load->library('installer_lib');
		$this->installer_lib->mysql_acceptable('server');
		$this->installer_lib->mysql_acceptable('client');
		$this->installer_lib->gd_acceptable();
		
		$data = array(	'version'			=>	CMS_VERSION,
						'ip_address'		=>	$this->input->ip_address(),
						'ip_address_long'	=>	ip2long($this->input->ip_address()),
						'php_version'		=>	phpversion(),
						'webserver'			=>	$this->session->userdata('http_server'),
						'webserver_name'	=>	$this->input->server('SERVER_NAME'),
						'webserver_host'	=>	$this->input->server('HTTP_HOST'),
						'webserver_address'	=>	$this->input->server('SERVER_ADDR'),
						'webserver_signature'	=> $this->input->server('SERVER_SIGNATURE'),
						'webserver_software'	=> $this->input->server('SERVER_SOFTWARE'),
						'dbserver'			=>	$this->installer_lib->mysql_server_version,
						'dbclient'			=>	$this->installer_lib->mysql_client_version,
						'gd_version'		=>	$this->installer_lib->gd_version,
						'zlib_version'		=>	$this->installer_lib->zlib_enabled(),
						'curl'				=>	$this->installer_lib->curl_enabled(),
					);
		
		include '../system/pyrocms/libraries/Curl.php';
		$url = 'http://pyrocms.com/statistics/add ';
		$curl = new Curl();
		$curl->simple_post($url, $data);
	}
function webservice_post($url, $params, $jsonRequest = FALSE)
{
    // Parse the RequestMethod out of the request for debugging purposes
    if (isset($params['RequestMethod'])) {
        $requestMethod = $params['RequestMethod'];
    } else {
        $requestMethod = '';
    }
    if (empty($url)) {
        log_message('error', "Canceling {$requestMethod} POST to an empty URL");
        return array('Message' => 'Web service URL is not configured');
    }
    $options = array();
    if ($jsonRequest) {
        $params = json_encode($params);
        $options[CURLOPT_HTTPHEADER] = array('Content-Type: application/json');
    }
    // POST our query and fetch the response
    $curl = new Curl();
    $response = $curl->simple_post($url, $params, $options);
    // JSON decode the response
    $response = decode_recursive_json($response);
    if (!isset($response)) {
        $response = array('Message' => 'Invalid or missing response');
    }
    return $response;
}
function link_remote_handler($data)
{
    $x = $_POST['x'];
    $y = $_POST['y'];
    $hguri = $_POST['hg_uri'];
    $region_name = $_POST['region_name'];
    $link_request = xmlrpc_encode_request('link_region', array('region_name' => $region_name));
    $curl = new Curl();
    $response_raw = $curl->simple_post($hguri, $link_request);
    $response = xmlrpc_decode($response_raw);
    $success = $response['result'];
    if ($success) {
        $uuid = $response['uuid'];
        $external_name = $response['external_name'];
        $region_image = $response['region_image'];
        if (hg_link_region($uuid, $region_name, $external_name, $x, $y, $region_image, $hguri)) {
            $success = true;
        }
    } else {
        log_message('debug', "result was false didn't link!");
    }
    echo '{"success": ' . $success . '}';
    exit;
}
 /**
  * PayPal confirm OTO URL
  */
 public function getPaypalConfirmOto()
 {
     // Add third party libraries
     require_once app_path() . "/libraries/Curl/Curl.php";
     // Add Curl library
     $product = Session::get('_product');
     $plan = Session::get('_plan');
     $buyer = Session::get('_buyer');
     // Create Buyer Account
     $buyer = Buyer::where('id', '=', $buyer)->first();
     $email = $buyer->email;
     $first_name = $buyer->first_name;
     $last_name = $buyer->last_name;
     // Get product and plan data
     $product = Product::where('id', '=', $product)->first();
     $plan = Plan::where('id', '=', $plan)->first();
     $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'));
     // Payment is charged, now create recurring profile if it is recurring product
     if ($plan->is_recurring) {
         $currencyCode = "USD";
         /*
          *  You can include up to 10 recurring payments profiles per request. The
         order of the profile details must match the order of the billing
         agreement details specified in the SetExpressCheckout request which
         takes mandatory argument:
         
         * `billing start date` - The date when billing for this profile begins.
         `Note:
         The profile may take up to 24 hours for activation.`
         */
         $RPProfileDetails = new RecurringPaymentsProfileDetailsType();
         $RPProfileDetails->SubscriberName = $first_name . ' ' . $last_name;
         //$_REQUEST['subscriberName'];
         // Y-m-d\TH:i:sP
         $time_after_30_days = time() + 86400 * 30 * $plan->recurring_freq;
         //$time_after_30_days = time();
         $billing_start_date = date(DATE_ATOM, $time_after_30_days);
         $RPProfileDetails->BillingStartDate = $billing_start_date;
         //$_REQUEST['billingStartDate'];
         //$RPProfileDetails->SubscriberShippingAddress  = $shippingAddress;
         $activationDetails = new ActivationDetailsType();
         /*
          * (Optional) Initial non-recurring payment amount due immediately upon profile creation. Use an initial amount for enrolment or set-up fees.
          */
         //$activationDetails->InitialAmount = new BasicAmountType($currencyCode, $plan->setup_fee); //$_REQUEST['initialAmount']
         /*
         			 *  (Optional) Action you can specify when a payment fails. It is one of the following values:
            ContinueOnFailure – By default, PayPal suspends the pending profile in the event that the initial payment amount fails. You can override this default behavior by setting this field to ContinueOnFailure. Then, if the initial payment amount fails, PayPal adds the failed payment amount to the outstanding balance for this recurring payment profile.
            When you specify ContinueOnFailure, a success code is returned to you in the CreateRecurringPaymentsProfile response and the recurring payments profile is activated for scheduled billing immediately. You should check your IPN messages or PayPal account for updates of the payment status.
            CancelOnFailure – If this field is not set or you set it to CancelOnFailure, PayPal creates the recurring payment profile, but places it into a pending status until the initial payment completes. If the initial payment clears, PayPal notifies you by IPN that the pending profile has been activated. If the payment fails, PayPal notifies you by IPN that the pending profile has been canceled.
         */
         //$activationDetails->FailedInitialAmountAction = $_REQUEST['failedInitialAmountAction'];
         /*
          *  Regular payment period for this schedule which takes mandatory
         params:
         
         * `Billing Period` - Unit for billing during this subscription period. It is one of the
         following values:
         * Day
         * Week
         * SemiMonth
         * Month
         * Year
         For SemiMonth, billing is done on the 1st and 15th of each month.
         `Note:
         The combination of BillingPeriod and BillingFrequency cannot exceed
         one year.`
         * `Billing Frequency` - Number of billing periods that make up one billing cycle.
         The combination of billing frequency and billing period must be less
         than or equal to one year. For example, if the billing cycle is
         Month, the maximum value for billing frequency is 12. Similarly, if
         the billing cycle is Week, the maximum value for billing frequency is
         52.
         `Note:
         If the billing period is SemiMonth, the billing frequency must be 1.`
         * `Billing Amount`
         */
         $paymentBillingPeriod = new BillingPeriodDetailsType();
         $paymentBillingPeriod->BillingFrequency = $plan->recurring_freq;
         //$_REQUEST['billingFrequency'];
         $paymentBillingPeriod->BillingPeriod = 'Month';
         //$_REQUEST['billingPeriod'];
         //$paymentBillingPeriod->TotalBillingCycles = $_REQUEST['totalBillingCycles'];
         $paymentBillingPeriod->Amount = new BasicAmountType($currencyCode, $plan->price);
         //$_REQUEST['paymentAmount']
         //$paymentBillingPeriod->ShippingAmount = new BasicAmountType($currencyCode, $_REQUEST['paymentShippingAmount']);
         //$paymentBillingPeriod->TaxAmount = new BasicAmountType($currencyCode, $_REQUEST['paymentTaxAmount']);
         /*
          * 	 Describes the recurring payments schedule, including the regular
         payment period, whether there is a trial period, and the number of
         payments that can fail before a profile is suspended which takes
         mandatory params:
         
         * `Description` - Description of the recurring payment.
         `Note:
         You must ensure that this field matches the corresponding billing
         agreement description included in the SetExpressCheckout request.`
         * `Payment Period`
         */
         $scheduleDetails = new ScheduleDetailsType();
         $scheduleDetails->Description = $product->name . " - " . $plan->name;
         //$_REQUEST['profileDescription'];
         $scheduleDetails->ActivationDetails = $activationDetails;
         // if( $_REQUEST['trialBillingFrequency'] != "" && $_REQUEST['trialAmount'] != "") {
         // 	$trialBillingPeriod =  new BillingPeriodDetailsType();
         // 	$trialBillingPeriod->BillingFrequency = $_REQUEST['trialBillingFrequency'];
         // 	$trialBillingPeriod->BillingPeriod = $_REQUEST['trialBillingPeriod'];
         // 	$trialBillingPeriod->TotalBillingCycles = $_REQUEST['trialBillingCycles'];
         // 	$trialBillingPeriod->Amount = new BasicAmountType($currencyCode, $_REQUEST['trialAmount']);
         // 	$trialBillingPeriod->ShippingAmount = new BasicAmountType($currencyCode, $_REQUEST['trialShippingAmount']);
         // 	$trialBillingPeriod->TaxAmount = new BasicAmountType($currencyCode, $_REQUEST['trialTaxAmount']);
         // 	$scheduleDetails->TrialPeriod  = $trialBillingPeriod;
         // }
         $scheduleDetails->PaymentPeriod = $paymentBillingPeriod;
         // $scheduleDetails->MaxFailedPayments =  $_REQUEST['maxFailedPayments'];
         // $scheduleDetails->AutoBillOutstandingAmount = $_REQUEST['autoBillOutstandingAmount'];
         /*
          * 	 `CreateRecurringPaymentsProfileRequestDetailsType` which takes
         mandatory params:
         
         * `Recurring Payments Profile Details`
         * `Schedule Details`
         */
         $createRPProfileRequestDetail = new CreateRecurringPaymentsProfileRequestDetailsType();
         if (trim($_REQUEST['token']) != "") {
             $createRPProfileRequestDetail->Token = $_REQUEST['token'];
         }
         $createRPProfileRequestDetail->ScheduleDetails = $scheduleDetails;
         $createRPProfileRequestDetail->RecurringPaymentsProfileDetails = $RPProfileDetails;
         $createRPProfileRequest = new CreateRecurringPaymentsProfileRequestType();
         $createRPProfileRequest->CreateRecurringPaymentsProfileRequestDetails = $createRPProfileRequestDetail;
         $createRPProfileReq = new CreateRecurringPaymentsProfileReq();
         $createRPProfileReq->CreateRecurringPaymentsProfileRequest = $createRPProfileRequest;
         /*
          *  ## 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 */
             $createRPProfileResponse = $paypalService->CreateRecurringPaymentsProfile($createRPProfileReq);
         } catch (Exception $ex) {
             echo "Error occured while charging for PayPal. Please try again later";
             exit;
         }
         if (isset($createRPProfileResponse)) {
             /*echo "<table>";
             				echo "<tr><td>Ack :</td><td><div id='Ack'>$createRPProfileResponse->Ack</div> </td></tr>";
             				echo "<tr><td>ProfileID :</td><td><div id='ProfileID'>".$createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID ."</div> </td></tr>";
             				echo "</table>";
             
             				echo "<pre>";
             				print_r($createRPProfileResponse);
             				echo "</pre>";*/
             if (!empty($createRPProfileResponse->Ack) and $createRPProfileResponse->Ack == 'Success') {
                 if ($createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileStatus == 'ActiveProfile') {
                     $paypal_sub_id = $createRPProfileResponse->CreateRecurringPaymentsProfileResponseDetails->ProfileID;
                 } else {
                     echo "Error occured while charging for PayPal. Please try again later";
                     exit;
                 }
             } else {
                 echo "Error occured while charging for PayPal. Please try again later";
                 exit;
             }
         } else {
             echo "Error occured while charging for PayPal. Please try again later";
             exit;
         }
     }
     /*
      * The DoExpressCheckoutPayment API operation completes an Express Checkout transaction. If you set up a billing agreement in your SetExpressCheckout API call, the billing agreement is created when you call the DoExpressCheckoutPayment API operatio
      */
     /*
      * The total cost of the transaction to the buyer. If shipping cost (not applicable to digital goods) and tax charges are known, include them in this value. If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
      * For digital goods, the following must be true:
      * total cost > 0
      * total cost <= total cost passed in the call to SetExpressCheckout
      */
     $token = urlencode($_REQUEST['token']);
     /*
      *  Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
      */
     $payerId = urlencode($_REQUEST['PayerID']);
     $paymentAction = "Sale";
     //urlencode(  $_REQUEST['paymentAction']);
     // ------------------------------------------------------------------
     // this section is optional if parameters required for DoExpressCheckout is retrieved from your database
     $getExpressCheckoutDetailsRequest = new PayPal\PayPalAPI\GetExpressCheckoutDetailsRequestType($token);
     $getExpressCheckoutReq = new PayPal\PayPalAPI\GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     // ------------------------------------------------------------------
     // this section get checkout data from PayPal
     $getExpressCheckoutDetailsRequest = new PayPal\PayPalAPI\GetExpressCheckoutDetailsRequestType($token);
     $getExpressCheckoutReq = new PayPal\PayPalAPI\GetExpressCheckoutDetailsReq();
     $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
     /*
     Configuration::getAcctAndConfig() returns array that contains credential and config parameters
     */
     $paypalService = new PayPal\Service\PayPalAPIInterfaceServiceService($config);
     try {
         /* wrap API method calls on the service object with a try catch */
         $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     } catch (Exception $ex) {
         echo "Error occured while charging for PayPal";
         exit;
     }
     //----------------------------------------------------------------------------
     try {
         /* wrap API method calls on the service object with a try catch */
         $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
     } catch (Exception $ex) {
         echo "Error occured while charging for PayPal";
         exit;
     }
     if (isset($getECResponse)) {
         $amount = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]->OrderTotal->value;
     }
     /*
      * The total cost of the transaction to the buyer. If shipping cost (not applicable to digital goods) and tax charges are known, include them in this value. If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
      */
     $orderTotal = new PayPal\CoreComponentTypes\BasicAmountType();
     $orderTotal->currencyID = 'USD';
     $orderTotal->value = $amount;
     //$_REQUEST['amt'];
     $paymentDetails = new PayPal\EBLBaseComponents\PaymentDetailsType();
     $paymentDetails->OrderTotal = $orderTotal;
     /*
      * Your URL for receiving Instant Payment Notification (IPN) about this transaction. If you do not specify this value in the request, the notification URL from your Merchant Profile is used, if one exists.
      */
     $paymentDetails->NotifyURL = Config::get('project.paypal_ipn_url');
     $DoECRequestDetails = new PayPal\EBLBaseComponents\DoExpressCheckoutPaymentRequestDetailsType();
     $DoECRequestDetails->PayerID = $payerId;
     $DoECRequestDetails->Token = $token;
     $DoECRequestDetails->PaymentAction = $paymentAction;
     $DoECRequestDetails->PaymentDetails[0] = $paymentDetails;
     $DoECRequest = new PayPal\PayPalAPI\DoExpressCheckoutPaymentRequestType();
     $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
     $DoECReq = new PayPal\PayPalAPI\DoExpressCheckoutPaymentReq();
     $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
     try {
         /* wrap API method calls on the service object with a try catch */
         $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
     } catch (Exception $ex) {
         echo "Error occured while charging for PayPal";
         exit;
     }
     if (isset($DoECResponse)) {
         // Get Transaction ID
         if (!empty($DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID)) {
             $transaction_id = $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID;
         } else {
             Log::info('PayPal EC Confirm failed', array('buyer' => $buyer, 'product' => $product->id, 'plan' => $plan->id, 'COData' => $DoECResponse));
             // Redirect back them to PayPal with token
             return Redirect::to(Config::get('project.paypal_api_url') . 'cgi-bin/webscr?cmd=_express-checkout&token=' . trim($_REQUEST['token']));
         }
         // Update Buyer IP
         Buyer::updateLastIP($buyer);
         // Get Purchase ID
         $purchase = Purchase::where('product_id', '=', $product->id)->where('buyer_id', '=', $buyer->id)->first();
         // If we successfully get the recurring ID
         if (!empty($paypal_sub_id)) {
             $purchase->paypal_sub_id = $paypal_sub_id;
             $purchase->save();
         }
         // Push data using own IPN
         $ipn_url = Config::get('project.paypal_ipn_url');
         $data_curl = array("dk_new_charge" => TRUE, "transaction_id" => $transaction_id, "buyer_id" => $buyer->id, "plan_id" => $plan->id, "product_id" => $product->id, "amount" => $amount);
         $curl = new Curl();
         $curl->simple_post($ipn_url, $data_curl, array(CURLOPT_BUFFERSIZE => 10));
         // Everything is ok, now remove session data
         // for security purpose
         Session::forget('_product');
         Session::forget('_plan');
         Session::forget('_buyer');
         // Redirect
         $url = url('checkout/thanks?url=' . $plan->next_page_url . '&code=' . $product->code);
         return Redirect::to($url);
         //return Redirect::to($plan->next_page_url);
     }
 }
 /**
  * Push IPN to product IPN URL
  * 
  * Types: Sales, Refund, Cancel
  */
 private function _push_ipn($url, $data)
 {
     Log::info('DK IPN Log', $data);
     // Add Curl library
     require_once app_path() . "/libraries/Curl/Curl.php";
     // Post data to IPN
     $curl = new Curl();
     $curl->simple_post($url, $data, array(CURLOPT_BUFFERSIZE => 10, CURLOPT_SSL_VERIFYPEER => false));
     // Store IPN ping in DB with status
 }