public function actionBullingInformation() { $this->pageName = "billing"; // if (!Yii::app()->request->isPostRequest) { // $this->redirect(basePath('')); // } if (Yii::app()->user->isGuest) { Yii::app()->request->redirect(basePath('')); } // if (UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), Yii::app()->user->getState('propertyId'), UserAccessTable::OWNER)) { // $this->redirect(basePath('')); // ; // } $model = new PayPalPaymentModel(); $model->setAttributes($_POST); $model->validate(); $errors = $model->getErrors(); if (count($errors) > 0) { $this->render('index', array('errors' => $errors, 'bull' => $model->attributes, 'countries' => $this->getCountries(), 'provinces' => $this->getProvinces())); return; } $userApi = sharedkeyApi::create('usersAPI'); $userApi->addParams(array('email' => Yii::app()->user->getState('email'), 'format' => 'json')); $property = Properties::model()->findByPk(Yii::app()->user->getState('propertyId')); $byEmail = json_decode($userApi->byEmail('get')); $userData = (array) $byEmail->data; $userData['prop_name'] = $property ? $property->property_name : ""; $response = PayPalHelper::createBullingRequest($model, $userData); if (!$response->status) { $errors['0'] = $response->errorMessage; $this->render('index', array('errors' => $errors, 'countries' => $this->getCountries(), 'provinces' => $this->getProvinces())); return; } //activate property $property->isdeactivated = 0; $property->trialPeriodStartDate = null; $property->edt = new CDbExpression('NOW()'); $property->save(); //update property Admin $user2property = User2property::model()->findByAttributes(array('propertyId' => $property->getAttribute('id'), 'access' => UserAccessTable::OWNER)); if ($user2property->getAttribute('userId') != Yii::app()->user->getState('id')) { //need update property admin $user2property->access = UserAccessTable::FULL_ACCESS; $user2property->save(); //find current payer link and set it to Admin mode $u2p = User2property::model()->findByAttributes(array('userId' => Yii::app()->user->getState('id'), 'propertyId' => $property->getAttribute('id'))); $u2p->access = UserAccessTable::OWNER; $u2p->save(); } $this->redirect(basePath('app/gallery')); }
/** * Generating an access token for the user * from the previously stored refresh token * false on no token * * @return String/boolean */ public static function generateAccessTokenFromRefreshToken($refresh_token) { $api_context = PayPalHelper::getApiContext(); try { // getting token info $token_info = new OpenIdTokeninfo(); $token_info = $token_info->createFromRefreshToken(array('refresh_token' => $refresh_token), $api_context); } catch (Exception $ex) { // something went wrong echo '<pre>'; print_r(json_decode($ex->getData())); exit(1); } // everything's fine, returning accessToken return $token_info->getAccessToken(); }
public static function confirmOrders($token) { $details = self::PPHttpPost('GetExpressCheckoutDetails', "TOKEN=" . $token); if ("SUCCESS" == strtoupper($details["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($details["ACK"])) { $checkout_details = $details; $httpParsedResponseAr = PayPalHelper::confirmCheckout($details); if ($httpParsedResponseAr != false) { $paypal_info = self::decodePaypalInfo($httpParsedResponseAr); return json_decode(json_encode(array('orders' => PayPalHelper::getOrderDetails($checkout_details), 'paypal_info' => $paypal_info))); // return PayPalHelper::getOrderDetails($checkout_details); } else { return false; } } else { return false; } }
/** * Unify charges from PayPal and Stripe * * @return array of all customers */ public static function getEvents($user) { // return array $allEvents = array(); $stripeEvents = array(); $paypalEvents = array(); // get charges from Stripe if connected if ($user->isStripeConnected()) { $stripeEvents = StripeHelper::getEvents($user); } // get plans from Paypal if connected if ($user->isPayPalConnected()) { // getting api context $apiContext = PayPalHelper::getApiContext(); $paypalPlans = PayPalHelper::getEvents($apiContext); } // merge the 2 arrays $allEvents = array_merge($stripeEvents, $paypalEvents); return $allEvents; }
public function showPaypal() { $api_context = PayPalHelper::getApiContext(); try { $params = array('access_token' => PayPalHelper::generateAccessTokenFromRefreshToken(Auth::user()->paypal_key)); $user = OpenIdUserinfo::getUserinfo($params, $api_context); } catch (Exception $ex) { print "no pp key"; } /* // Create a new instance of Plan object $plan = new Plan(); // # Basic Information // Fill up the basic information that is required for the plan $plan->setName('Welltakeyourmoney') ->setDescription('If you register we can take all your money.') ->setType('fixed'); $paymentDefinition = new PaymentDefinition(); // The possible values for such setters are mentioned in the setter method documentation. // Just open the class file. e.g. lib/PayPal/Api/PaymentDefinition.php and look for setFrequency method. // You should be able to see the acceptable values in the comments. $paymentDefinition->setName('Regular Payments') ->setType('REGULAR') ->setFrequency('Month') ->setFrequencyInterval("5") ->setCycles("12") ->setAmount(new Currency(array('value' => 999, 'currency' => 'USD'))); // ### Create Plan $merchantPreferences = new MerchantPreferences(); $merchantPreferences->setReturnUrl(route('auth.dashboard')) ->setCancelUrl(route('auth.dashboard')) ->setAutoBillAmount("yes") ->setInitialFailAmountAction("CONTINUE") ->setMaxFailAttempts("0") ->setSetupFee(new Currency(array('value' => 9999, 'currency' => 'USD'))); $plan->setPaymentDefinitions(array($paymentDefinition)); $plan->setMerchantPreferences($merchantPreferences); $request = clone $plan; try { $output = $plan->create($api_context); } catch (PayPal\Exception\PPConnectionException $ex) { echo '<pre>';print_r(json_decode($ex->getData())); exit(1); } */ try { $params = array('page_size' => '20'); $planList = Plan::all($params, $api_context); } catch (PayPal\Exception\ConnectionException $ex) { echo '<pre>'; print_r(json_decode($ex->getData())); exit(1); } Log::info($planList); try { $plan = Plan::get("P-0TA38541GG196850X3XYQ2KI", $api_context); } catch (PayPal\Exception\ConnectionException $ex) { echo '<pre>'; print_r(json_decode($ex->getData())); exit(1); } return View::make('dev.paypal', array('output' => $plan)); }
public function actionRemoveproperty($id) { $userId = Yii::app()->user->getState('id'); //all users can remove itself from property member's list if (!UserAccessTable::checkUser2PropertyAccess($userId, $id, UserAccessTable::GUEST)) { Yii::app()->request->redirect(basePath('app/gallery')); } $user2property = User2property::model()->findByAttributes(array('userId' => $userId, 'propertyId' => $id)); if ($user2property->getAttribute('access') != UserAccessTable::OWNER) { //email to member (NOT admin) $this->layout = "emailmaster"; $body = $this->render("../emails/emailItselfRemove", array('name' => $user2property->user->getAttribute('firstname') . ' ' . $user2property->user->getAttribute('lastname'), 'propertyName' => $user2property->property->getAttribute('property_name')), true); MailHelper::send($body, "SharedKey - Removed Property", array($user2property->user->getAttribute('email'))); //clear calendar events first $calendar = new Calendar(); $calendar = $calendar->findAllByAttributes(array('linkid' => $user2property->getAttribute('id'))); foreach ($calendar as $cal) { $cal->delete(); } //for not property Administrator we just remove a link to property $user2property->delete(); if ($this->_isAllUserPropertiesDeactivated($userId)) { //removed last property need remove user $this->removeUser($userId); return; } Yii::app()->request->redirect(basePath('app/properties')); return; } //member is administrator we need cancel RecurringPaymentsProfile and deactivate property //lets find last transaction $transaction = Transaction::model()->findByAttributes(array('userid' => $userId, 'propertyid' => $id)); if (!$transaction) { //no previous transactions not need to refund } $userApi = sharedkeyApi::create('usersAPI'); $userEmail = Yii::app()->user->getState('email'); $userApi->addParams(array('email' => $userEmail)); $byEmail = json_decode($userApi->byEmail('get')); $userData = (array) $byEmail->data; $userData['property_id'] = $id; //close RecurringPaymentsProfile if ($transaction) { YII::app()->user->setState("addPropertyEmailed", true); $temp = PayPalHelper::cancelRecurringPaymentsProfile($transaction->getAttribute('pp_PROFILEID'), $userData); } //do deactivated $property = Properties::model()->findByPk($id); $property->isdeactivated = 1; $property->edt = new CDbExpression('NOW()'); //$property->trialPeriodStartDate = null; $property->save(); $this->layout = "emailmaster"; //mail to admin $token = uniqid(); $body = $this->render("../emails/emailAdminAfterRemove", array('name' => Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'), 'propertyName' => $property->getAttribute('property_name'), 'url' => basePathByHost("/app/changeactiveproperty/" . $property->getAttribute("id")) . '?token=' . $token), true); MailHelper::send($body, "SharedKey - Removed Property", array($userEmail)); //informative other user about property deactivated $users2properties = User2property::model()->with('user')->findAll('propertyId=:propertyId', array(':propertyId' => $id)); foreach ($users2properties as $key => $u2p) { if ($u2p->getAttribute('access') == UserAccessTable::OWNER) { continue; } } if ($this->_isAllUserPropertiesDeactivated($userId)) { $user = User::model()->find('id=:id', array(':id' => $userId)); $user->verificationToken = $token; $user->save(); $this->redirect(basePath('user/logout')); return; } Yii::app()->request->redirect(basePath('app/properties')); }
public function actionTest() { PayPalHelper::SetExpressCheckout('12', '*****@*****.**'); }
public static function cancelRecurringPaymentsProfile($profileId, $userData) { $pp_nvpstr = ''; $pp_nvpstr = $pp_nvpstr . "METHOD=ManageRecurringPaymentsProfileStatus"; $pp_nvpstr = $pp_nvpstr . "&PROFILEID=" . $profileId; $pp_nvpstr = $pp_nvpstr . "&ACTION=Cancel"; $pp_nvpstr = $pp_nvpstr . "&NOTE=SharedKey.com - One-year subscription for a single property canceled."; return PayPalHelper::SendRequest($pp_nvpstr, $userData); }