Ejemplo n.º 1
0
 public function getClientToken($params = [])
 {
     if (!isset($this->clientToken)) {
         $this->clientToken = ClientToken::generate($params);
     }
     return $this->clientToken;
 }
Ejemplo n.º 2
0
 public function startPartial()
 {
     try {
         $this->braintreeClientToken = ClientToken::generate();
     } catch (Throwable $e) {
         response()->unavailable('Braintree payments are not available at the moment');
     }
     $record = BraintreeRecord::create(['order_id' => $this->order->getId(), 'user_id' => auth('frontend')->user('id') ?? null, 'order_hash' => $this->order->getIdString(), 'braintree_hash' => sha1(microtime() . $this->order->getIdString()), 'braintree_client_token' => $this->braintreeClientToken, 'state' => 'started', 'data' => json_encode(['billIds' => $this->order->getBills()->map('id')]), 'braintree_payment_method_nonce' => null, 'braintree_transaction_id' => null, 'price' => null, 'error' => null, 'dt_started' => Carbon::now(), 'dt_confirmed' => null]);
     return $record;
 }
 public function getClientToken()
 {
     $clientToken = Braintree_ClientToken::generate();
     return $clientToken;
 }
Ejemplo n.º 4
0
 public function testErrorsWhenInvalidArgumentIsSupplied()
 {
     $this->setExpectedException('InvalidArgumentException', 'invalid keys: customrId');
     Braintree\ClientToken::generate(array("customrId" => "1234"));
 }
Ejemplo n.º 5
0
 public function test_GenerateRaisesExceptionOnGateway422()
 {
     $this->setExpectedException('InvalidArgumentException', 'customer_id');
     Braintree\ClientToken::generate(array("customerId" => "not_a_customer"));
 }
function Insert_Subscribe_Now($atts)
{
    /** @var string $redirect_page
     * @var string $login_page
     * @var string $Time
     * @var string $Salt
     * @var string $omit_fields
     */
    // Include the required global variables, and create a few new ones
    global $wpdb, $user_message, $feup_success;
    global $ewd_feup_fields_table_name, $ewd_feup_user_table_name, $ewd_feup_user_fields_table_name;
    $CheckCookie = CheckLoginCookie();
    $Sql = "SELECT * FROM wp_ewd_feup_fields WHERE Field_Show_In_Front_End='Yes' ORDER BY `Field_Order` ASC";
    $Fields = $wpdb->get_results($Sql);
    $User = $wpdb->get_row($wpdb->prepare("SELECT * FROM wp_ewd_feup_users WHERE Username='******'", $CheckCookie['Username']));
    $UserData = $wpdb->get_results($wpdb->prepare("SELECT * FROM wp_ewd_feup_user_fields WHERE User_ID='%d'", $User->User_ID));
    $user_id = $User->User_ID;
    $email = $User->user_email;
    $phone = $User->Username;
    $first_name = '';
    $last_name = '';
    if (is_object($UserData)) {
        $userdata = get_object_vars($UserData);
        $first_name = $userdata["First Name"];
        $last_name = $userdata["Last Name"];
    }
    $output = '';
    //If payment/subscription submitted
    if (isset($_POST["payment_method_nonce"])) {
        $nonce = $_POST["payment_method_nonce"];
        $payment_method = Braintree\Customer::create(['firstName' => $first_name, 'lastName' => $last_name, 'email' => $email, 'phone' => $phone, 'paymentMethodNonce' => $nonce]);
        $result = Braintree\Subscription::create(['paymentMethodToken' => $payment_method->customer->defaultPaymentMethod()->token, 'planId' => SUBSCRIPTION_PLAN_ID]);
        if ($result->success) {
            $query = "UPDATE `wp_ewd_feup_users` SET `subscription`='active' WHERE User_ID = {$user_id};";
            $num_row = $wpdb->query($query);
            if ($num_row === false) {
                error_log("Failed to execute query {$query} \n", 3);
            }
            $query = "UPDATE `wp_ewd_feup_user_fields` SET `Field_Value`=null WHERE `Field_Name` = 'Membership Expiry Date' AND User_ID = {$user_id};";
            $num_row = $wpdb->query($query);
            if ($num_row === false) {
                error_log("Failed to execute query {$query} \n", 3);
            }
            session_start();
            $_SESSION['user_updated'] = "Your subscription is now active.";
            if (!headers_sent()) {
                header("Location: /you-did-it");
            }
            error_log("success!: " . $result->transaction->id);
        } else {
            if ($result->transaction) {
                $output .= print_r("Error processing transaction:", true);
                $output .= print_r("\n  code: " . $result->transaction->processorResponseCode, true);
                $output .= print_r("\n  text: " . $result->transaction->processorResponseText, true);
            } else {
                $output .= print_r("Validation errors: \n", true);
                $output .= print_r($result->errors->deepAll(), true);
            }
        }
        return $output;
    }
    //else, render payment form
    $clientToken = \Braintree\ClientToken::generate();
    $output = '<form id="checkout" method="post" action="/subscribe-now">
                  <div id="payment-form"></div>
                  <input type="submit" value="Get 3 Days Free">
                </form>

<script src="https://js.braintreegateway.com/js/braintree-2.22.2.min.js"></script>
<script>

var clientToken = "' . $clientToken . '";

braintree.setup(clientToken, "dropin", {
  container: "payment-form"
});
</script>
';
    return $output;
    $Custom_CSS = get_option("EWD_FEUP_Custom_CSS");
    $Sql = "SELECT * FROM {$ewd_feup_fields_table_name} WHERE Field_Show_In_Front_End='Yes' ORDER BY `FIELD_ORDER` ASC";
    $Fields = $wpdb->get_results($Sql);
    $User = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$ewd_feup_user_table_name} WHERE Username='******'", $CheckCookie['Username']));
    $UserData = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$ewd_feup_user_fields_table_name} WHERE User_ID='%d'", $User->User_ID));
    $ReturnString = "";
    $output = "";
    $output .= "<script> var \$user_id= {$User->User_ID} ; </script>";
    $ReturnString .= $output;
    wp_enqueue_script('your_settings', '/wp-content/js/subscribe_now.js', array('jquery'));
    return $ReturnString;
}
Ejemplo n.º 7
0
 public static function decodedClientToken($params = array())
 {
     $encodedClientToken = Braintree\ClientToken::generate($params);
     return base64_decode($encodedClientToken);
 }
 /**
  * Get the default JavaScript variables for Spark.
  *
  * @return array
  */
 public static function scriptVariables()
 {
     return ['braintreeMerchantId' => config('services.braintree.merchant_id'), 'braintreeToken' => Spark::billsUsingBraintree() ? BraintreeClientToken::generate() : null, 'cardUpFront' => Spark::needsCardUpFront(), 'collectsBillingAddress' => Spark::collectsBillingAddress(), 'collectsEuropeanVat' => Spark::collectsEuropeanVat(), 'csrfToken' => csrf_token(), 'currencySymbol' => Cashier::usesCurrencySymbol(), 'env' => config('app.env'), 'roles' => Spark::roles(), 'state' => Spark::call(InitialFrontendState::class . '@forUser', [Auth::user()]), 'stripeKey' => config('services.stripe.key'), 'userId' => Auth::id(), 'usesApi' => Spark::usesApi(), 'usesBraintree' => Spark::billsUsingBraintree(), 'usesTeams' => Spark::usesTeams(), 'usesStripe' => Spark::billsUsingStripe()];
 }
Ejemplo n.º 9
0
 /**
  * @param array $params
  * @return \Braintree\Result\Successful|\Braintree\Result\Error|null
  */
 public function generate(array $params = [])
 {
     try {
         return ClientToken::generate($params);
     } catch (\Exception $e) {
         return null;
     }
 }