Hi,

Been looking for a way to get value of items within a handler object. From the below i would need to call the value of the image with console.log(this.image);. I doubt that is the way to do it. but I cannot find something that can point me in the right direction. Everthing i try comes up and undefined on 6th line.

<script>
        var handler = StripeCheckout.configure({
          key: "pk_test_6pRNASCoBOKtIshFeQd4XMUh",
          image: "images/admin_imgs/podcastpilot.jpg",
          token: function(token) {
            console.log(this.image);
            var stripeToken = token.id;
            var stripeEmail = token.email;
            $.post(
                "/stripe.php", /* your route here */
                { stripeToken: token.id, stripeEmail: stripeEmail },
                function(data) {
                  console.log(data);
                }
            );
          }
        });
        $("body").on("click", "button#customForm", function(e) {
            // Open Checkout with further options
            handler.open({
              name: $(this).attr("data-name"),
              description: $(this).attr("data-desc")+\' ($\'+$(this).attr("data-price")/100+\')\',
              amount: parseInt($(this).attr("data-price"))
            });
            e.preventDefault();
          });
      </script> 

Recommended Answers

All 2 Replies

Yeah, this.image wouldn't work. This has no context. You're just defining a variable. Why not attach an ID to the image and then retrieve the object via jQuery?

All the other things like name, amount, desc, are generated through the on click function. I need to gather those to send to the $.post so I can process them with php. I was trying to play with the image value so i can see how it works but I really need those items.

I guess the best route is to create an object and add to it like the below. What do you think?

<script>
        var objvalues = {};
        var handler = StripeCheckout.configure({
          key: "pk_test_6pRNASCoBOKtIshFeQd4XMUh",
          image: "images/admin_imgs/podcastpilot.jpg",
          token: function(token) {
            objvalues["stripeToken"] = token.id;
            objvalues["stripeEmail"] = token.email;
            $.post(
                "/stripe.php", /* your route here */
                objvalues,
                function(data) {
                  console.log(data);
                }
            );
            console.log(objvalues.name);
            objvalues = {};
          }
        });
        $("body").on("click", "button#customForm", function(e) {
            // Open Checkout with further options
            objvalues["name"]=$(this).attr("data-name");
            objvalues["description"] = $(this).attr("data-desc")+\' ($\'+$(this).attr("data-price")/100+\')\';
            objvalues["amount"] = parseInt($(this).attr("data-price"));
            handler.open({
              name: objvalues.name,
              description: objvalues.description,
              amount: objvalues.amount
            });
            e.preventDefault();
          });
      </script>

I only thought about this direction after sleeping. sleep does wonders

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.