I want to save a Stripe card_id to my database based on the JSON response. I'm playing with the examples from the Stripe documentation right now:
customer = Stripe::Customer.retrieve("cus_3Ek7h52yGbLpQo")
customer.cards.create(:card => {:number => "4242424242424242",
:exp_month => 10, :exp_year => 2014})
The JSON looks like this:
#<Stripe::Card:0x3ff2f0191540> JSON: {"id":"card_3GHjrJqMgoyTNy","object":"card","last4":"4242","type":"Visa","exp_month":10,"exp_year":2014,"fingerprint":"Ds0FdzrOSdYMkwC0","customer":"cus_3Ek7h52yGbLpQo","country":"US","name":null,"address_line1":null,"address_line2":null,"address_city":null,"address_state":null,"address_zip":null,"address_country":null,"cvc_check":null,"address_line1_check":null,"address_zip_check":null}
In my controller, after creating the credit card, how can I parse the JSON to get only the card id? Is it even possible?
You should be able to get the credit card from the response like this:
#card = customer.cards.create(:card => {:number => "4242424242424242",
:exp_month => 10, :exp_year => 2014})
#card.id #this should have the card id in it
Related
I am creating the following pay request with the ruby adaptive payment sdk:
fee = 2
api = PayPal::SDK::AdaptivePayments.new
pay = api.build_pay({
:actionType => "PAY",
:cancelUrl => "https://localhost:3000/purchases/paypal_cancelled?purchase_guid=" + self.guid,
:currencyCode => self.currency,
:feesPayer => "PRIMARYRECEIVER",
:ipnNotificationUrl => "http://paypal.corstiaan.ultrahook.com/purchases/paypal_ipn_notify?purchase_guid=" + self.guid,
:receiverList => {
:receiver => [{
:amount => 20,
:email => seller#email.com,
:primary => true
}, {
:amount => fee,
:email => 'ch-facilitator#corstiaan.com'
}],
},
:returnUrl => "https://localhost:3000/purchases/paypal_success?purchase_guid=" + self.guid + "&verification_key=" + paypal_verification_key })
pay_response = api.pay(pay)
Everything works just like I want it to. I am the facilitator of the transaction and secondary receiver and the seller is the primary receiver. This is all ok. Also, the cancel and return urls are being called correctly.
Only the ipnNotificationUrl is not getting hit. I have set up a forward using ultrahook.com which is getting called correctly when using paypal's ipn simulator (that does not support adaptive ipn messages for some reason...) so technically that forward should work, but I never see anything hitting my server...
I am lost in the paypal docs, which are terrible.
When I view the IPN history ch-facilitator#corstiaan.com I only see IPN messages that relate to the payment of the fee from the seller to facilitator, nothing regarding the whole transaction which should be posted to ipnNotificationUrl if I understand correctly up to this point.
What am I doing wrong/what can be the problem? Thanks!
I am having a requirement to create contacts using Salesforce-Bulk-API in salesforce account. My question is can we also create custom fields for Contact object in salesforce using bulk API?
salesforce = SalesforceBulkApi::Api.new(#client)
records_to_insert = Array.new
socialcrm_list.socialcrm_list_records.each do |record|
new_record = {"FirstName" => record.first_name, "LastName" => record.last_name, "Email" => record.email1, "Phone" => record.phone1, "HomePhone" => record.phone3, "MobilePhone" => record.phone2, "MailingStreet" => record.address1, "MailingCity" => record.city,"MailingState" => record.state, "MailingCountry" => record.country, "MailingPostalCode" => record.zip, "CustomField" => record.job}
records_to_insert.push(new_record)
I have tried passing CustomField as an attribute in the hash, but it is not working. Is there any way we can pass extra attributes in Hash without adding them exclusively from Salesforce developer Account
Attached a reference image of sales-force custom attribute form over here
A customer object can have many cards in Stripe.com. How do you charge an existing card?
I've tried a few things, but the stripe api for some reason borks when to get an old customer token and a new card token instead of just creating a new card on that customer. So I've gone the route of retrieving all the customer's cards, then selecting one by radio button, then submitting the token of the chosen card into a charge
charge = Stripe::Charge.create(
:amount => "#{#subscription.price}",
:currency => "usd",
:card => params[:existing_card_id],
:description => "Subscription for #{current_user.email}"
)
but I get the error
Stripe::InvalidRequestError: Invalid token id: card_24j3i2390s9df
I figured this out.
With existing card tokens you have to send in the customer token as well
charge = Stripe::Charge.create(
:amount => "#{#subscription.price}",
:currency => "usd",
:customer => current_user.stripe_customer_id,
:card => params[:existing_card_id],
:description => "Subscription for #{current_user.email}"
)
This answer help to ME apply the same solution in PHP for charge an specific credit card customer, other than the default credit card. Here the pieces:
JSON:
{
"charge": {
"amount":122,
"currency":"usd",
"customer":"cus_7hVsgytCc79BL7",
"card":"card_17SENFJ4sx1xVfmD8skoSjNs"
}
}
PHP
$item = $params->request->getJsonRawBody();
$new_charge = \Stripe\Charge::create(array(
"amount" => $this->ConvertAmount($item->charge->amount),
"currency" => $item->charge->currency,
"customer" => $item->charge->customer,
"card" => $item->charge->card
));
return $new_charge;
I'm working with the Amazon Product Advertising API and I'm trimming its responses within my controller to render customized JSON, but its responses change a lot depending on the product category, so I need to write code that can catch all of the ways it changes. I only need a few pieces of data, so how can I simply check to see if those pieces exist within Amazon's API response before including them in my own custom JSON?
Note: I'm using this gem to integrate with Amazon's API. It returns the API responses in its own objects.
#results = (Amazon's API response)
#custom_response = []
#results.items.each do |product|
#new_response = OpenStruct.new(
:id => product.asin,
:source => "amazon",
:title => product.title,
:price => #product_price,
:img_small => #images[0],
:img_big => #images[1],
:category => product.product_group,
:link => "http://amazon.com/" )
#custom_response << #new_response
end
You can try something like this:-
#new_response = OpenStruct.new(:source => "amazon", :link => ".....")
#new_response.id = product.asin if product.asin.present?
#new_response.title = product.title if product.title.present?
other attributes....
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")