How do you use the Gibbon Gem to automatically add subscribers to specific interest groups in MailChimp? - ruby-on-rails

I'm trying to figure out how I can use the Gibbon gem in Rails to automatically add subscribers to specific interest groups in MailChimp?
I've found this article which details a non-Rails method for doing so: http://roman.tao.at/uncategorized/mailchimp-api-listsubscribe-listbatchsubscribe-and-groups/
I'd like to figure out how to implement that functionality using the Gibbon gem: https://github.com/amro/gibbon
FYI, I'm also a novice with both MailChimp and Rails.

Finally, after hours of perusing through code. I've found the example I'm looking for!
Thanks to TJ Moretto for providing this on a Google Groups thread:
I'm using the gibbon gem, but ran into the same types of issues.
Here's how I had to format the parameters to finally get this to work:
gb.list_subscribe({:id => "#{list.id}",
:email_address => user.email,
:update_existing => true,
:double_optin => false,
:send_welcome => false,
:merge_vars => {'FNAME' => "#{user.first_name}",
'LNAME' => "#{user.last_name}",
'GROUPINGS' => {0 => {'id' => grouping.id, 'groups' => "#{challenge.name}"}}}
})
Hope that helps.
Mailchimp Team - based on the number of issues that everyone runs into
when trying to do this (across all programming languages), I suggest
you update the API documentation to be more clear.

Update for version 2.0 of the MailChimp API and version 1.0 of Gibbon (For #Calin and posterity). Here are the necessary changes from the previous version. The API object is accessed like this now:
gb = Gibbon::API.new
And list methods like so:
gb.lists.subscribe(params)
Finally the :email_address parameter has been replaced by the :email parameter, which should be given a value of the following form: The value should itself be a hash with one key, either 'email' or 'leid', and the value should be either the email address of the subscriber or MC's unique identifier (LEID) for the subscriber.
So a full subscription call might look something like this:
gb = Gibbon::API.new
gb.lists.subscribe(:id => "ed6d1dfef4",
:email =>
{ "email" => "example#domain.com" },
:merge_vars =>
{:groupings =>
{
0 => { :id => "95", :groups => ["Some Group", "Another Group"]},
1 => { :id => "34", :groups => ["A Third Group"]}
}
},
:update_existing => "true",
:double_optin => "false",
:replace_interests => "false")

Related

Setting business name and header images with adaptive payments on paypal

In order to ensure consistent experience i want to set header image and business on paypal's page, view items with their names and description and ask the customer to select shipping address.
I'm using active_paypal_adaptive_payment gem (https://github.com/jpablobr/active_paypal_adaptive_payment) and the option to set_payment_options:
response = ADAPTIVE_GATEWAY.setup_purchase(
:action_type => 'CREATE',
:receiver_list => recipients,
...
)
ADAPTIVE_GATEWAY.set_payment_options(
:display_options => {
:business_name => 'Big Business',
:header_image_url => 'url goes here'
},
:sender_options => {
:require_shipping_address_selection => true },
:receiver_options => [{
:description => _description,
:invoice_data => {
:item => [{
:name => _title,
:item_count => 1,
}],
:total_shipping => 10.0,
:total_tax => 10
},
:receiver => {
:email => email
}
}])
)
The issue is that it doesn't work - i do not see any business names or image, i see generic names on the left column (the one with the items and the flow doesn't ask for shipping address).
Could you please advise?
You can also do so by logging into PayPal, then going to My Selling Tools and update the Custom payment pages option to create a new page style with the color combination and logo of your choice (there are size restrictions for the logo images)

ActiveMerchant PayPal Express possible bug?

I am a little bit confused, somehow I am able to change the amount of the purchase:
First I setup my purchase,
#setup_response = gateway.setup_purchase(
10*100,
:ip => request.remote_ip,
:return_url => url_for(:controller => "payments", :action => 'confirm', :only_path => false),
:cancel_return_url => url_for(:controller => "payments", :action => 'error', :only_path => false),
:currency => 'EUR',
:email => current_user.email,
:no_shipping => true,
:items => items
)
Later I do the purchase:
purchase = gateway.purchase(
500*100,
:ip => request.remote_ip,
:payer_id => params[:payer_id],
:token => params[:token],
:currency => 'EUR'
)
As you can see I have changed the amount from 10 -> setup/user agreed to 1000 when purchasing and it did work in the Paypal Sandbox.
I think this is really strange. Can anybody confirm this? This should not happen?
Is this perhaps only possible in the Sandbox?
Pretty sure Paypal Express Checkout does not require the amount at DoExpressCheckoutPayment (which is what setup_purchase maps to) to be the same as that at SetExpressCheckout. To quote Paypal's documentation:
In the simplest case, you set the total amount of the order when you
call the SetExpressCheckout API. However, you can change the amount
before calling the DoExpressCheckoutPayment API if you did not know
the total amount when you called the SetExpressCheckout API.
You are allowed some leeway between the set-up and the purchase - this is to allow people changing their order, discounts, etc.
Don't take the risk of billing people more than you clearly state - Paypal are very quick to give people refunds so you'll end up losing out in the long run.

How do I process responses from using the official Chargify gem in Rails 3.

I'm currently developing a Rails application to accept recurring billing using Chargify. I've installed their gem and managed to connect to Chargify with the gem. However, some subscriptions go through and some do not.
My question is how do I handle or even process the response once the gem communicates with the server?
I don't see anything in the development logs that gives me any indication of a successful data transfer or a failed one. The gem documentation also does not mention anything regarding this.
Thanks for looking.
UPDATE
The code I'm playing around with is in my checkout controller:
def checkout
#customer = Customer.new(params[:customer])
Chargify::Customer.create(
:first_name => "Charlie",
:last_name => "Bull",
:email => "charlie#example.com",
:organization => "Chargify"
)
Chargify::Subscription.create(
:product_handle => 'recurring',
:customer_attriburtes => {
:first_name => #customer.shipping_first_name,
:last_name => #customer.shipping_last_name,
:email => #customer.email
},
:payment_profile_attributes => {
:first_name => #customer.shipping_first_name,
:last_name => #customer.shipping_last_name,
:full_number => "1",
:expiration_month => 1,
:expiration_year => 2012,
:billing_address => #customer.shipping_street_address,
:billing_city => #customer.shipping_city,
:billing_state => #customer.shipping_state,
:billing_zip => #customer.shipping_zip_code,
:billing_country => #customer.shipping_country
}
)
#if #subscription.save
# logger.info "saved description"
# redirect_to process_path
#else
# redirect_to :back, :alert =>"There was an error."
#end
end
The customer create is going through, but the Subscription does not. I'm just looking for a callback from the server so I can act based off whether it succeeded and find out why the subscription isn't going through.
Since this whole gem uses ActiveResource cant you just call something like:
# Create a subscription from a customer reference
subscription = Chargify::Subscription.create(
:customer_reference => 'moklett',
:product_handle => 'chargify-api-ares-test',
:credit_card_attributes => {
:first_name => "Michael",
:last_name => "Klett",
:expiration_month => 1,
:expiration_year => 2020,
:full_number => "1"
}
)
if subscription.save
puts "Created Subscription!"
else
puts "Subscription Failed!"
end
and see if the record has been created correctly?
EDIT: Your code should work but I see that the call to save is commented out. When you call save it creates or updates the record and testing this should allow you to determine if your record was created or not.

RiCal add_attendee issue

I am using RiCal gem to create calendar event in my ROR project. The issue i have is when i add attendee it adds the attendee as .
ATTENDEE:mailto:sanjay.swain#in.ibm.com
ATTENDEE:mailto:sanjayswa#gmail.com
But I want ATTENDEE as
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=
TRUE;CN=sanjay.swain#in.ibm.com;X-NUM-GUESTS=0:mailto:sanjay.swain#in.ibm.c
om
with ROLE, PARTSTAT etc.. Is there a way to get this result using RiCal gem..
I found the solution. Here is what I have done:
options = {'CUTYPE' => 'INDIVIDUAL','RSVP' => 'TRUE','ROLE' => 'REQ-PARTICIPANT','PARTSTAT' => 'NEEDS-ACTION','X-NUM-GUESTS' => '0'}
attendee_property = RiCal::PropertyValue::CalAddress.new(nil, :value => "mailto:"+attend, :params => options)
event.attendee_property = attendee_property

Ruby on Rails / Yellow Maps For Ruby Plugin woes

Okay I've read through the plugin comments and the docs as well and I have yet to come up with an answer as to how to do this. Here's my problem I want to use the :info_window_tabs and the :icon option, but I don't know what format to pass my information in. According to the documentation the following code should be correct. Here's my code:
#mapper.overlay_init(GMarker.new([map.lat, map.lng],
:title => map.name,
:info_window_tabs => [
{:tab => "HTML", :content => #marker_html},
{:tab => "Attachments", :content => "stuff"}],
:icon => {
:image => "../images/icon.png"
}))
The readme and documentation can be viewed here.
And the relevant ruby file that I am trying to interact with, including the author's comments, can be viewed here.
I have tried the #rubyonrails channel in IRC as well as emailing the author directly and reporting an issue at GitHub. It really is just a question of syntax.
Thanks!
Okay, so I finally got this figured out. Here's how you do it; :icon accepts a GIcon variable and :info_window_tabs accepts an array of GInfoWindowTabs. Here is how you would declare each with the plugin.
Declare GIcon
#mapper.icon_global_init(GIcon.new(:image => "../images/civil.png",
:icon_anchor => GPoint.new(0,0),
:shadow => "../images/shadow.png",
:shadow_size => GSize.new(37,32),
:info_window_anchor => GPoint.new(9,2)), "civil_icon")
#civil_icon = Variable.new("civil_icon")
Declare GInfoWindowTab
#tab1 = GInfoWindowTab.new('Tab 1 Label', 'HTML for inside of tab1')
#tab2 = GInfoWindowTab.new('Tab 2 Label', 'HTML for inside of tab2')
#window_tabs = [#tab1, #tab2]
Then in your GMarker declaration just do the following:
#mapper.overlay_init(GMarker.new([map.lat, map.lng],
:title => map.name,
:icon => #civil_icon,
:max_width => 300,
:info_window_tabs => #window_tabs))
And you're done.

Resources