I have been following the https://medium.com/ruby-on-rails-development/google-places-gem-21e9e1aac491 tutorial and am having trouble integrating the Google Places gem with my code to fetch Google reviews for my application.
I have enabled Google places and got the respective API key. I have also enabled the business account and subscribed to 1-month free trial. However, I am getting this message now.
You must enable Billing on the Google Cloud Project at console.cloud.google.com/project/_/billing/enable Learn more at developers.google.com/maps/gmp-get-started.
doctors_controller.rb
def show
#doctor = Doctor.find(params[:id])
authorize #doctor, :manage?
#doctor = #location = #doctor.decorate
#tring out google reviews
api_key = "My_key"
#client = GooglePlaces::Client.new(api_key)
end
show.html.erb
<h1><%= #client.spots(-33.8670522, 151.1957362, :name => 'italian') %></h1>
thanks in advance, cheers
Related
Payments are going through stripe but customers are not being created in the Stripe dashboard. There is already code to create customer that is called, but the API to create customer is not listed in the Stripe dashboard logs:
def create_customer(stripe_token, email)
customer = Stripe::Customer.create(source: stripe_token, email: email)
customer.save
end
Am I missing anything? It was working fine before Nov 2022.
I want customers to be able to update their credit card details in my Rails app. Stripe has documentation on how to achieve this, but the article is showing an example in PHP, but I need an example for Rails: https://stripe.com/docs/recipes/updating-customer-cards
Basically, I need to save a customer's credit card without charging it.
This is subscribers_controller.rb:
class SubscribersController < ApplicationController
before_filter :authenticate_user!
def new
end
def update
token = params[:stripeToken]
customer = Stripe::Customer.create(
card: token,
plan: 1212,
email: current_user.email
)
current_user.subscribed = true
current_user.stripeid = customer.id
current_user.save
redirect_to profiles_user_path
end
end
You might also want to check out this SO answer How to create a charge and a customer in Stripe ( Rails) for more details on using Stripe in a Rails application.
For Ruby documentation, you can find great examples at on the Stripe Ruby API. In Stripe terminology, a card is called a source for the customer. You can create a source from a token, but once it's created, you deal with source and default_source elements on the Customer object, and retrieve card objects from the customer's source. Also note that you should never try to use the token beyond creating the source (or for one-time charges).
The Stripe Ruby API for Customers shows that you can create a customer and assign the source at the same time:
customer = Stripe::Customer.create(
source: token,
email: current_user.email
)
You do not have to assign a source to create a customer. However, if you set the customer up on a subscription, they will require a source to be available, and the charges will be made to the customer's default_source. If a customer has only one source, it is automatically the default_source.
The Stripe Ruby API for Cards, shows that you can also add a new card to an existing customer, using a token:
customer = Stripe::Customer.retrieve(customer_id)
customer.sources.create({source: token_id})
Once you have a card assigned to the customer, you can make it the default_source, using this:
customer.default_source = customer.sources.retrieve(card_id)
And that's what it takes to get setup and ready to start charging customers. Happy billing!
To update the card for an existing customer, the relevant snippet from the PHP recipe you mentioned is:
$cu = \Stripe\Customer::retrieve($customer_id); // stored in your application
$cu->source = $_POST['stripeToken']; // obtained with Checkout
$cu->save();
In Ruby, this would be:
cu = Stripe::Customer.retrieve(customer_id)
cu.source = params[:stripeToken]
cu.save
This will update the existing customer with the card from the token contained in the stripeToken parameter.
I have a rails app and I want to use the twitter api with the account of a user (to make favs, tweets, etc ...).
Here is my problem, I want the user to be able to create several "Project" with one different twitter account by project.
That is why I want to get the access_token and the access_token_secret but store them in my Project model and not in my User model.
I don't understand how I can do that. All the stuffs I found explain every time the way to do it with Omniauth and a "sign up"/"Sign in" of the User.
I'm very new to this Oauth / callback / API stuff so I'm a bit lost.
Is there an easy way to just get the access_token and the access_token_secret and store it where I want ?
I managed to do it with saving information i needed in the session.
def ask_twitter_authorisation
session[:info] = #project
redirect_to "/auth/twitter"
end
and then use it in my callback
def twitter_callback
session_hash = session[:info]
#project = Project.find(session_hash["id"])
#project.t_access_token = auth_hash.credentials.token
#project.t_access_token_secret = auth_hash.credentials.secret
#project.save
end
I want to get a visitor groups. It works just fine when I am connected with my account (the administrator of the app) but when I connect with another account the groups.count == 0
def index
if (#current_visitor)
#graph = Koala::Facebook::API.new(#current_visitor.oauth_token)
groups = #graph.get_connections("me", "groups").select
puts groups.count
end
end
end
You need to ask user for groups permission.
In case you're using omniauth-facebook, just add :scope => 'user_groups' to your configuration, besides app id and app secret.
Detail of permission with facebook login can be found here https://developers.facebook.com/docs/facebook-login/permissions/v2.2
I'm building a marketplace application that uses PayPal Express. I've got a form for sellers to input their PayPal API credentials, but I need a way to validate them by making some sort of call to PayPal.
I'm using the PaypalExpressGateway in ActiveMerchant, and I don't see anything other than the standard purchase controls. Is there any sort of null-operation that can be used?
Any help would be greatly appreciated!
I am using the TransactionSearch operation for this purpose. By specifying STARTDATE=2100-01-01 00:00:00 it basically results in a no-op.
It will validate the credentials for you, without requiring any additional input from the seller.
For security reasons there isn't a way to check if the email is a valid paypal account. You can always make a small transaction and then void it if account validity is really required.
I don't have the answer personally. But I know Ryan Bates of Railscasts.com has recently devoted six (!) episodes to ActiveMerchant and Paypal in particular. Check out episodes #141 through #146 at railscasts.com.
Ok, after 4 hours...
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaypalExpressGateway < Gateway
def get_balance(options = {})
commit 'GetBalance', build_get_balance_request(options)
end
private
def build_get_balance_request(options)
xml = Builder::XmlMarkup.new :indent => 2
xml.tag! 'GetBalanceReq', 'xmlns' => PAYPAL_NAMESPACE do
xml.tag! 'GetBalanceRequest', 'xmlns:n2' => EBAY_NAMESPACE do
xml.tag! 'n2:Version', API_VERSION
xml.tag! 'n2:ReturnAllCurrencies', '1'
end
end
xml.target!
end
end
end
end
class SellerMerchantValidator < ActiveModel::Validator
def validate(record)
paypal_attrs = ['paypal_api_username', 'paypal_api_password', 'paypal_api_signature']
if record.paypal_merchant? && (record.changed - paypal_attrs).size < record.changed.size # one of paypal_attrs changed
response = record.gateway.get_balance
unless response.params['balance'].present?
record.errors[:base] << "Please check the PayPal details and make sure all three are entered correctly."
end
end
end
end
Thanks to Neils for the idea to check the TransactionSearch.
Please let me know if there is a better way to check if any of the api field changed.
There is also a call for GetBalance in the API.
Some sample code
Looks like the simplest (and quickest?) way.
Right, so if you want to test a user's credentials using ActiveMerchant, use the transaction_search method on the gateway
https://github.com/Shopify/active_merchant/blob/cb72e0f9c58f57b1293e6e976229b26cfbfee6a8/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb
This example will return a success (make sure to fill in your test credentials)
#username = ''
#password = ''
#signature = ''
gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(
login: #username,
password: #password,
signature: #signature,
test: true
)
gateway.transaction_search({start_date: DateTime.now})
PayPal does have an AddressVerify API. It confirms whether a postal address and postal code match those of the specified PayPal account holder. I'm in the process of implementing it on our website right now, in fact.
You can read more about it here:
https://www.x.com/docs/DOC-1162#id0862M0QH02L
and here:
https://cms.paypal.com/us/cgi-bin/?&cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_AddressVerify