Neil Watt

Joined

70 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Subscriptions with Stripe Discussion

I think the way to do it is with the new elements method (as opposed to the customer form method) is to use the customer id to get the "default source" object to retrieve the card. And then from there to retrieve everything from the card object that's returned but I'm just not sure about the syntax.

Posted in Subscriptions with Stripe Discussion

Hi, thanks for this tutorial. I am reading that now stripe has deprecated the custom form method and is moving to the elements UI method (https://github.com/mage2pro.... Following the elements ui method I managed to get the payments to go through by copying in the examples on the stripe site and using the same controller format as you used. However, I'm having problems retrieving the card info in the way you did that was previously different with the custom form method. Any idea how to do that with the element ui method they are moving to? Thanks

This is my subscribe new view, I kept the javascript in the view.

<h1>Subscribe!</h1>

<%= form_tag subscription_path, id: "payment-form" do%>
<form action="/subscription" method="post" id="payment-form">
<div class="form-row">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element">

</div>

<div id="card-errors" role="alert"></div>
</div>

<button>Submit Payment</button>
</form>
<% end %>

<script>

//var stripe = Stripe('#############');
var stripe = Stripe($("meta[name='stripe-key']").attr("content"));
var elements = stripe.elements();

// Custom styling can be passed to options when creating an Element.
var style = {
base: {
// Add your base input styles here. For example:
fontSize: '16px',
lineHeight: '24px'
}
};

// Create an instance of the card Element
var card = elements.create('card', {style: style});

// Add an instance of the card Element into the `card-element` <div>
card.mount('#card-element');

card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}

});

// Create a token or display an error when the form is submitted.
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();

stripe.createToken(card).then(function(result) {

if (result.error) {
// Inform the user if there was an error
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
// Send the token to your server
stripeTokenHandler(result.token);

}
});
});

function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server

var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
form.submit();

}

</script>

Posted in Recurring events with the ice_cube gem Discussion

Thanks again, much appreciated I'll try that. Cheers

Posted in Recurring events with the ice_cube gem Discussion

Sorry to bother you again but would really appreciate any tips of adapting this. I was trying to adapt your calendar_events method for use in saving all the instances of a recurring event from the events controller create method. Any idea how I could adapt this to generate and save all recurring events for a new instance of an event? My create method in event controller code is below. I think I just need to tweak it a little as it works for all the existing saved events but i specifically just want it to pass the new event through to the method.

My aim is this: user creates new event with recurrence rule, then on save it loops through all occurrences of this instance up until some predefined end time creating an array of the associated events which are subsequently saved after being generated. The difference here is that rather than fetching all the already saved events and looping through the occurrences, I want to do that only for the new instance that the user is creating when they open up the form.
/////events controller code

def create
## first testing for whether recurring is null or not
#room have one to many relationship to events

if params[:event][:recurring] == "null"

room = Room.find(params[:room_id])
@event = room.events.new(event_params)
@event.save
else

room = Room.find(params[:room_id])
#this loops through all already saved events and #then creates an array of occurances for each saved #event whereas I am trying to do this for only the #instance of the event being created not every event #already saved

@calendar_events = room.events.flat_map{ e|e.calendar_events(params.fetch(:start,Time.zone.now).to_date)}
@calendar_events.each(&:save)

end

end

///event modelcode

#I made a modification to the calendar_events method to account for one to many relationshi with rooms to events, and I am using start instead of start_date

def calendar_events(startit)
if recurring.empty?
[self]
else

end_date = startit.end_of_month.end_of_week

schedule(start).occurrences(end_date).map do |date|

@event = room.events.new(room_id: room_id, title: title, start: date, end: date, color: color, recurring: recurring)

end
end
end

Posted in Recurring events with the ice_cube gem Discussion

Thanks, much appreciated that makes sense I'll give it a shot. I'm realising I have to weigh up the advantage of saving space by accessing serialised events versus the convenience of querying actual event records in DB. I really liked the way you used recurrence select with ice cube and wanted to keep that approach.

Posted in Recurring events with the ice_cube gem Discussion

Thanks for your reply. Lol a little bit. I'm trying to make a basic scheduling app so that different users can search each others calendar schedules for available time slots and arrange meetings. From the user's standpoint; each user adds events to their calendar which take up a time slot. Their availability is then determined to be those time slots with no events (in practice slightly more complex than this but for now this is what I'm looking at). Then the user's search (of another user's calendar) would be something like:

"All time slots (for the another user) from datetime x to datetime y across one calendar with no events present".

The purpose would be to schedule a meeting for instance. The way I thought of the problem was to put all events matching given search date range criteria into an array that would appear as "search results". This would avoid the necessity of going into every user's calendar manually to check availability that way. It's quite simple to do that with discrete non-recurring events as you are querying discrete objects out of a database. But because the serialise methodology is not generating all the events in a series at once unless you load up the calendar for each user it seems a little more complex to do that.

Posted in Recurring events with the ice_cube gem Discussion

Hi, thanks for the tutorial I found it very helpful. I wondered if you had any thoughts on the best way to query recurring events that have been serialised using the recurring gem? The issue I'm running into is if an individual who has not created the original calendar events wanted to search several calendars (created by other users) for free slots at given times the serialiser method then seems to become more complex than if we'd created individual discrete events. For example if you wanted to share calendars between different users. Would be interested to know your thoughts on this. Thanks