Javascript回调和自定义条带签出处理程序

Javascript回调和自定义条带签出处理程序,javascript,callback,stripe-payments,Javascript,Callback,Stripe Payments,主要是工作和传递令牌和价格到我的后端根据答案进行了一些更改,但仍然无法从createBookingSuccessful回调获取预订id,以便将令牌和我的令牌一起传递到我的后端。javascript非常新,简单的条带签出一开始还不错,但现在我需要使用自定义方法从第三方预订回调传递预订id function initalizeWidget(duration, title, price, contractor) { var widget = new TimekitBooking(); wi

主要是工作和传递令牌和价格到我的后端根据答案进行了一些更改,但仍然无法从createBookingSuccessful回调获取预订id,以便将令牌和我的令牌一起传递到我的后端。javascript非常新,简单的条带签出一开始还不错,但现在我需要使用自定义方法从第三方预订回调传递预订id

function initalizeWidget(duration, title, price, contractor) {
   var widget = new TimekitBooking();
   widget.init({
   app_key: 'live_widget_key_zr3c9idDjH',
   resources: [
      '1b6097f9-4806-3dec48c8'
    ],

    callbacks: {
      createBookingSuccessful: function(response)  {
        if (response.data) {
          // Update the booking)id here.
           var booking_id = response.data.id;
           console.log(booking_id);
           handler = StripeCheckout.configure(stripeCheckoutConfig);
           handler.open({
           name: contractor,
           description: title,
           zipCode: true,
           amount: price
         });
         // ...
      }
    }
  },   
 });
}


var stripeCheckoutConfig = {
  image:  'https://stripe.com/img/documentation/checkout/marketplace.png',
  locale: 'auto',
  key: 'pk_test_O9AlqrUIlJTH2a5V0e',

  token: function(token) {
    // Get the booking_id;
  var booking_id = this.booking;
   // Send the charge through
  $.post("/subscription/web/payment-method/",
    { token: token.id, price: {{ task_price_cents }}, booking_id:   booking_id}, function(data) {
  if (data["status"] == "ok") {
    window.location = "/some-url/";
  } else {
    // Deal with error
    alert(data["message"]);
  }
});
}
};

// Simply pass the config.
var handler = StripeCheckout.configure(stripeCheckoutConfig);

您可以使用
数据
对象来存储有关
应用程序
的所有信息

/**
 * Your application's data (everything related to your booking 
 * system on the client-side)
 * It can be accessed by the Objects/Functions in the same scope.
 */
var appData = {
  booking_id: null,
  handler: null
};

/**
 * Widget init
 */
var widget = new TimekitBooking();
widget.init({
  // ...
  callbacks: {
    createBookingSuccessful: function(response)  {
      if (response.data) {
        // Update the booking id here. 
        appData.booking_id = response.data.id;
        // ...
      }
    }
  }
};

// Pass the config.
appData.handler = StripeCheckout.configure({
  // ...
  token: function(token) {
    // Get the booking_id;
    var booking_id = appData.booking_id;
    // Send the charge through
    $.post(
      "/subscription/web/payment-method/",
      { token: token.id, price: {{ task_price_cents }}, booking_id: appData.booking_id },
      // ...
    );
  }
});

var handler = appData.handler;

谢谢,仍然在玩这个,但是在控制台中得到这个条带警告:StripeCheckout.configure:unrecogned选项'booking_id'。您可以在签出文档和回调中了解可用的配置选项。在configuration.booking\u idMy Bad的配置中未定义!我以为所有的代码都是你写的。Stripe是一个图书馆!我会更新我的答案。