Internal server error when saving card in paypal vault - ruby-on-rails

I am using pay-pal vault to store my users credit card. When am trying to store user credit card am getting internal server error with response code = 500. I have tried with different type of sample test cards, but still it is not working for me. Please save me from this issue.
credit_card = {
number: "5183330730754255",
type: "mastercard",
expire_month: 11,
expire_year: 2018,
cvv2: "874",
first_name: "Joe",
last_name: "Shopper",
billing_address: {
line1: "52 N Main St.",
city: "Johnstown",
country_code: "US",
postal_code: "43210",
state: "OH",
phone: "408-334-8890"
},
external_customer_id: "nodedeveloper122"
}
result = Typhoeus.post(
'https://api.sandbox.paypal.com/v1/vault/credit-cards/',
:params => credit_card,
:headers => {"Content-Type" => "application/json", "Authorization" => "Bearer ************"}
)

Related

Update an Array[JSON] for a POST request in api/v1 of a ruby application

I'm leraning Ruby and I'm trying to create an API to update all the players with a single POST request.
I have to update all the players which have the "ids" on the request.
The post request is given in Array[JSON] form, so I have to compare all the ids for every JSON with the players in the database and I have to update those who have the id specified.
Here the code of the post request:
{
"players": [
{
"player_id": 1,
"shirt_number": "25",
"speed": "47",
"agility": "80",
"shot": "62",
"step": "24",
"technique": "70",
"contrasts": "59",
"resistance": "65",
"parades": "25",
"aggressiveness": "60",
"coldness": "50"
},
{
"player_id": 2,
"shirt_number": "11",
"speed": “52",
"agility": “78",
"shot": “65",
"step": “23",
"technique": “60",
"contrasts": “19",
"resistance": “44",
"parades": "25",
"aggressiveness": "60",
"coldness": "50"
}
]
}
Here there is the code and the parameters:
desc 'Update a team'
params do
requires :players, type: Array[JSON] do
requires :id, type: Integer, desc: "Player ID"
requires :shirt_number, type: String, desc: "Shirt Number"
requires :speed, type: String, desc: "Speed"
requires :agility, type: String, desc: "Agility"
requires :shot, type: String, desc: "Shot"
requires :step, type: String, desc: "Step"
requires :technique, type: String, desc: "Technique"
requires :constrasts, type: String, desc: "Constrasts"
requires :resistance, type: String, desc: "Resistance"
requires :parades, type: String, desc: "Parades"
requires :aggressiveness, type: String, desc: "Aggressiveness"
requires :coldness, type: String, desc: "Coldness"
end
end
post 'update_team' do
params[:players].each do |player|
p = Player.find_by(id: params[:id])
p.update(player)
end
end
But it doesn't work! I didn't find anything about that. Someone can help me? Thank you very much in advance!
p = Player.find_by(id: params[:id]) -> From what you've posted, there isn't an id parameter and if there was, that would be referencing the same parameter each time through your loop. I think what you want is p = Player.find_by(id: player['player_id'])
Also keep in mind that Player.find_by(id: some_value) is looking at the database ID, which I imagine might be different from the player_id. If this is the case, then player_id should probably be a different column in your players table and you would instead do .find_by(player_id: player['player_id'])
Additionally, if you are just updating the record in place, you should use update!

STRIPE NameError: undefined local variable or method `request' for main:Object

I am trying to update a connected account so it can accept the terms of service and be able to create a payout. however, when I try to run the code in the console so it updates it doesn't update and that error regarding the ip address pops up. I am following stripe's documentation to update accounts.
I have tried not including ip into the tos_acceptance, but the ip is neccessary!
I tried 'ip' and putting quotes around request.remote_ip
"acct_id_12345", {
tos_acceptance: {
date: Time.now.to_i,
ip: request.remote_ip,
},
},
)
the error that appears is:
NameError: undefined local variable or method `request' for main:Object
You're running the code somewhere where the request method does not exist, eg. outside of a controller.
I just needed to name the request variable this is the final product:
account = Stripe::Account.create({
country: "US",
type: "custom",
requested_capabilities: ["transfers", "card_payments"],
email: current_user.email,
business_type: "company",
company: {
name: business.name,
address: {
city: business.city,
country: 'US',
line1: business.address,
postal_code: business.zip_code,
state: business.state,
},
phone: '3128880912',
tax_id: '000000000',
},
external_account: {
country: "US",
object: "bank_account",
account_number: params[:account_number],
routing_number: params[:routing_number],
},
settings: {
payouts: {
schedule: {
interval: 'monthly',
monthly_anchor: 1,
},
},
},
business_profile: {
url: business.website,
mcc: 5734,
},
tos_acceptance: {
date: Time.now.to_i,
ip: '181.48.147.209',
},
})

Passing API POST to stripe with business type?

Stripe news API update for Connect accounts doesn't allow the "legal_entity" param for new stripe accounts. The new updated way is for "business_type".. But the issue i have is that I need to pass data from either of the 2 choices for business_type of "individual" or "company.
This is the old way that worked:
acct = Stripe::Account.create({
:country => stripe_account_params[:country],
:type => "custom",
legal_entity: {
first_name: stripe_account_params[:first_name].capitalize,
last_name: stripe_account_params[:last_name].capitalize,
type: stripe_account_params[:account_type],
dob: {
day: stripe_account_params[:dob_day],
month: stripe_account_params[:dob_month],
year: stripe_account_params[:dob_year]
},
address: {
line1: stripe_account_params[:address_line1],
city: stripe_account_params[:address_city],
state: stripe_account_params[:address_state],
postal_code: stripe_account_params[:address_postal]
},
ssn_last_4: stripe_account_params[:ssn_last_4]
},
tos_acceptance: {
date: Time.now.to_i,
ip: request.remote_ip
}
})
The new way (my attempt):
acct = Stripe::Account.create({
:country => stripe_account_params[:country],
:type => "custom",
:business_type => stripe_account_params[:account_type],
requested_capabilities: ['card_payments'],
# company: {
# name: stripe_account_params[:business_name],
# phone: stripe_account_params[:business_phone],
# phone: stripe_account_params[:business_tax_id],
# address: {
# line1: stripe_account_params[:business_address_line1],
# city: stripe_account_params[:business_address_city],
# state: stripe_account_params[:business_address_state],
# postal_code: stripe_account_params[:business_address_postal]
# },
# },
individual: {
address: stripe_account_params[:address_line1],
first_name: stripe_account_params[:first_name],
last_name: stripe_account_params[:last_name],
ssn_last_4: stripe_account_params[:ssn_last_4],
# phone: stripe_account_params[:business_tax_id],
dob: {
day: stripe_account_params[:dob_day],
month: stripe_account_params[:dob_month],
year: stripe_account_params[:dob_year]
},
address: {
line1: stripe_account_params[:address_line1],
city: stripe_account_params[:address_city],
state: stripe_account_params[:address_state],
postal_code: stripe_account_params[:address_postal]
},
},
tos_acceptance: {
date: Time.now.to_i,
ip: request.remote_ip
}
})
With the section i have commented out, not commented out, I get this error:
(If i choose individual with the commented out area, it will work)
I tried simply not defining the address, etc. and loosely having the params and see if Stripe will decide where they go and that didn't work so it seems as if they need to be defined like above but i don't know how to distinguish them.
You cannot provide both company and individual parameters. Only
provide them accordingly with the business_type on the account.
Now, the fields are named the same within stripe:
https://stripe.com/docs/api/accounts/create
So i am unsure how i can pass this through. Any suggestions on how to do this?

Create external_account for Stripe Connect payouts with Stripe.js (iOS)

I am trying to connect actual bank accounts to the stripe accounts in Stripe Connect.
However, I am struggling with the actual implementation.
I use Custom Accounts, so I want to provide the user with the account creation logic through my iOS app.
In the Stripe API Reference it says that the recommended way to accomplish this is:
"Destination accounts are added via the external_accounts parameter when creating or updating Custom accounts. The value should be a bank account or debit card token returned from Stripe.js."
Creating the token is documented as follows (I am using NodeJS):
stripe.createToken('bank_account', {
country: 'US',
currency: 'usd',
routing_number: '110000000',
account_number: '000123456789',
account_holder_name: 'Jenny Rosen',
account_holder_type: 'individual',
}).then(function(result) {
// Handle result.error or result.token
});
Where to I link that token in the account creation process? See related code below:
app.post('/create_account', (req, res) => {
console.log('create account called');
var email = req.body.email;
var firstname = req.body.firstname;
var lastname = req.body.lastname;
stripe.accounts.create({
country: "CH",
type: "custom",
email: email,
business_name: "examplename",
legal_entity: {
first_name: "firstname",
last_name: "lastname",
dob: {
day: 1,
month: 1,
year: 1900
}
}
}).then((account) => {
res.status(200).send(account)
}).catch((err) => {
console.log(err, req.body)
res.status(500).end()
});
});
Is the token creation just a means of validating the account information client-side?
Would be glad if someone can elaborate on this with a simple step-by-step explanation, thank you in advance!
You'd pass the token in the external_account parameter:
var bankAccountToken = req.body.stripeToken;
stripe.accounts.create({
country: "CH",
type: "custom",
// ...
external_account: bankAccountToken,
}).then((account) => {
// ...

iOS facebook login response does not contain profile data

I implemented Facebook login for both Android and iOS using react-native-facebook-login. I followed all of the instructions and it is working perfectly on Android. It works on iOS, but the response does not contain profile data.
Android Response:
declinedPermissions: [],
provider: 'facebook',
profile:{
id: '121212121212121212',
name: 'XYZ',
email: 'xyz#gmail.com',
first_name: 'XYZ',
last_name: 'XYZ',
age_range: { min: 21 },
link: 'https://www.facebook.com/app_scoped_user_id/121212121212121212/',
picture: { data: { is_silhouette: false,url: 'https://scontent.xx.fbcdn.net/v/t1.0-1/12/12.jpg?oh=12&oe=12' } },
gender: 'male',
locale: 'en_US',
timezone: 5.5,
updated_time: '2017-02-01T08:16:35+0000',verified: true },
type: 'success',
credentials: {
permissions: [ 'public_profile', 'contact_email', 'user_friends', 'email' ],
tokenExpirationDate: '2017-05-13T14:56:36.690+0530',
userId: '1212121212121212121',
token:'ababababababababbababababa' }
But on iOS, the response is incomplete and there is no profile data:
declinedPermissions: [],
credentials: { tokenExpirationDate: '2017-05-14T14:58:09+05:30',
permissions: [ 'email', 'contact_email', 'user_friends', 'public_profile' ],
userId:'12121212121212121',
token:'abababababababababababababa' },
missingPermissions: []
The code is same for both Android and iOS. And I did all of the configuration changes in Xcode. Is there something else that needs to be done to get the profile data on iOS?
We need to do another API call where we send the token which was generated into this API call.
fetch('https://graph.facebook.com/v2.5/me?fields=email,name,first_name,last_name,friends&access_token=' + YOUR_GENERATED_TOKEN)
.then((response) => response.json())
.then((json) => {
})
.catch(() => {
reject('ERROR')
})
This call will give you the profile details.

Resources