function firstStep() { validateParameters($_POST); $planId = "basic"; $passThrough = array("address" => $_POST['addr'], "extended_addr" => $_POST['extended_addr'], "city" => $_POST['city'], "state" => $_POST['state'], "zip_code" => $_POST['zip_code']); try { /* * Calling ChargeBee Checkout new Hosted Page API to checkout a new subscription * by passing plan id the customer would like to subscribe and also passing customer * first name, last name, email and phone details. The resposne returned by ChargeBee * has hosted page url and the customer will be redirected to that url. * * Note: Parameter embed(Boolean.TRUE) can be shown in iframe * whereas parameter embed(Boolean.FALSE) can be shown as seperate page. * Note : Here customer object received from client side is sent directly * to ChargeBee.It is possible as the html form's input names are * in the format customer[<attribute name>] eg: customer[first_name] * and hence the $_POST["customer"] returns an associative array of the attributes. */ $hostUrl = getHostUrl(); $result = Chargebee_HostedPage::CheckoutNew(array("subscription" => array("planId" => $planId), "customer" => $_POST['customer'], "embed" => "false", "passThruContent" => json_encode($passThrough), "redirectUrl" => $hostUrl . "/checkout_two_step/redirect_handler", "cancelUrl" => $hostUrl . "/checkout_two_step/signup.html")); $redirectUrl = $result->hostedPage()->url; $jsonResponse = array("forward" => $redirectUrl); print json_encode($jsonResponse, true); } catch (ChargeBee_InvalidRequestException $e) { handleInvalidRequestErrors($e, "subscription[plan_id]"); } catch (Exception $e) { handleGeneralErrors($e); } }
function callingIframeCheckoutPage() { header('Content-Type: application/json'); validateParameters($_POST); $planId = "basic"; try { $result = ChargeBee_HostedPage::CheckoutNew(array("subscription" => array("planId" => $planId), "customer" => $_POST['customer'], "embed" => "true", "iframeMessaging" => "true")); /* * Sending hosted page url and hosted page id as response. */ $response = array("url" => $result->hostedPage()->url, "hosted_page_id" => $result->hostedPage()->id, "site_name" => ChargeBee_Environment::defaultEnv()->getSite()); print json_encode($response); } catch (ChargeBee_InvalidRequestException $e) { handleInvalidRequestErrors($e, "subscription[plan_id]"); } catch (Exception $e) { handleGeneralErrors($e); } }
<?php /* * Adding ChargeBee php libraries and configuration files. */ require_once dirname(__FILE__) . "/Config.php"; require_once dirname(__FILE__) . "/Util.php"; require_once dirname(__FILE__) . "/ErrorHandler.php"; /* Checkouts the existing subscription to active state for the passed * subscription id which is in trial state. */ if ($_POST) { validateParameters($_POST); try { /* Request the ChargeBee server to get the hosted page url. * Passing Timestamp as ZERO to the trial end will immediately change the * subscription from trial state to active state. * Note: Parameter embed specifies the returned hosted page URL * is shown in iframe or as seperate page. */ $hostUrl = getHostUrl(); $result = Chargebee_HostedPage::checkoutExisting(array("subscription" => array("id" => $_POST["subscription_id"], "trial_end" => 0), "embed" => "false", "redirect_url" => $hostUrl . "/checkout_existing/redirect_handler", "cancel_url" => $hostUrl . "/checkout_existing/profile.html")); $redirectURL = $result->hostedPage()->url; /* * This will redirect to the ChargeBee server. */ header("Location: {$redirectURL}"); } catch (Exception $e) { customError500($e); } }
$apiResponse = json_decode(file_get_contents($API_QUERY . '?' . $apiQuery)); $items = $apiResponse->items; if (isset($_GET['debug'])) { header('Content-Type: text/plain'); echo "Query: {$apiQuery}\n\n"; echo "Query API Response:\n"; echo json_encode($apiResponse, JSON_PRETTY_PRINT); foreach ($items as $item) { echo "\n"; echo "WP API response:\n"; echo json_encode(getMetadataFor($item), JSON_PRETTY_PRINT); echo "\n"; echo $item; echo ": "; echo createItemLink($item); } exit; } return $items; } /* * Actual handling * */ validateParameters(); if (isBrowserRequest()) { sendBrowserResponse(); } else { sendLinkedDataResponse(); } // vim: sw=4 ts=4:
function updateShippingAddress() { header('Content-Type: application/json'); validateParameters($_POST); try { $result = ChargeBee_Subscription::update(getSubscriptionId(), array("shipping_address" => $_POST['shipping_address'])); $jsonResponse = array("forward" => "/ssp-php/subscription"); print json_encode($jsonResponse, true); } catch (ChargeBee_InvalidRequestException $e) { handleInvalidRequestErrors($e); } catch (Exception $e) { handleGeneralErrors($e); } }
/** * Unfollow a user * * @param Request $request * @return Response */ public function unfollowAction(Request $request) { $data = $request->json()->get('Follow'); if (!validateParameters($data)) { return showErrorResponse("Format should be: {'Follow': {'follower_id': <int>, 'following_id: <int>}}", HTTP_UNPROCESSABLE_ENTITY); } if (isset($data['follower_id'])) { $follower_id = $data['follower_id']; } else { $follower_id = convertFbIdToId($data['follower_fb_id']); } if (isset($data['following_id'])) { $following_id = $data['following_id']; } else { $following_id = convertFbIdToId($data['following_fb_id']); } if ($follower_id === false || $following_id === false) { return showErrorResponse('No such user', HTTP_ACCEPTED, CONSTANTS::ERROR_CODE_GENERAL); } try { $follow_data = new Follow(); $follow_data->unfollowUser($follower_id, $following_id); // TODO: Add Notification::deleteByFromToUserIds() here } catch (\Exception $e) { return showErrorResponse($e->getMessage()); } $json_return[KeyParser::data] = array(KeyParser::user => Users::getStatistics($following_id), KeyParser::message => 'Success'); return response()->json($json_return); }