Set default country for phone number field in Stripe Connect onboarding? - ruby-on-rails

This is pretty minor, but for better UX, during stripe connect onboarding, I would like the phone number field to default to the connected user's country (just like the address field does). How can I make this happen? Note that I do not have the user's phone number, so I can't provide it as a parameter to Account.create()
Reproducible example
Create an new account and onboarding link
country = "US"
Stripe.api_key = Rails.application.credentials[Rails.env.to_sym][:stripe][:secret_stripe_test_key]
account = Stripe::Account.create({
country: country,
type: 'express',
capabilities: {
card_payments: {
'requested': true,
},
transfers: {
'requested': true,
},
},
settings: {
payouts: {
schedule: {
interval: "manual"
}
}
}
})
account_links = Stripe::AccountLink.create({
account: account.id,
refresh_url: 'https://example.com/reauth',
return_url: 'https://example.com/return',
type: 'account_onboarding',
})
When visiting the onboarding link (i.e. via account_links.url), despite the account's country being "US", the phone number defaults to Australia:
Question
How can I make the phone number field default to the country of the account?
Note
The address field does default to USA, as desired:

Unfortunately, you can not make stripe set country code for phone field based on country parameter you have sent. Stripe does not consider the country parameter for setting phone. If phone field is null, then it fills it automatically.

Related

Stripe: Change currency depending on location?

I have set USD as the default currency on my product but added 4 more currencies (EUR, GBP, AUD and CHF). How can I make these swap depending on the customers physical location. For the sake of an example, let's assume you are from Germany and want to buy my product - I want your displayed currency to automatically set itself to EUR during checkout.
<script>
var stripe = Stripe(
"pk_live_51LzJXLEOzrDWipQGPi4HbwFv1xxGw7wty7jifLYuKU9VwfpNvCb1DIfDohwHfJSk9VKQ1BhdpDIR8bVnjA9fEzR200y8nDoKqj"
)
document.getElementById("checkout").addEventListener("click", function(){
stripe.redirectToCheckout({
lineItems: [
{
price: 'price_1MKKUgEOzrDWipQGG2tTXjxV',
quantity: 1,
},
],
mode: 'payment',
successUrl: `https://galusfilms.com/luts=success`,
cancelUrl: `https://galusfilms.com/luts=cancel`,
})
.then(function(result){
});
})
</script>
This it what my current checkout session looks like, what do I need to add? I have very little experience in coding and all of this stuff and because of this I would really appreciate some help...
Since the price you've created supports multiple currencies, Stripe Checkout automatically localizes and presents the local currency to your customers in either USD, EUR, GBP, AUD or CHF in this case.
To test your currency presentment in AUD, when creating the Checkout session, you can pass test+location_AU#example.com in the customer_email parameter. Your code will look something like this:
const session = await stripe.checkout.sessions.create({
line_items: [{price: '{{PRICE_ID}}', quantity: 1}],
mode: 'payment',
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
customer_email: 'test+location_AU#example.com',
});
To see more details on how to test currency presentments you can visit this document.

How to integrate SCA Stripe Checkout with Stripe Connect using Rails 5

I've been trying to enable payments to users (sellers in this case) on my site. I've managed to allow the seller to set up their own Stripe account, and then their Stripe account ID is saved in the database.
However, I can't manage to allow people to pay the sellers. I've been looking at the Stripe docs and although very detailed, I can't figure out where everything is meant to go. I would like something like this:
I have got a new charge view, and this code is supposed to be in it I think:
// Initialize Stripe.js with the same connected account ID used when creating
// the Checkout Session.
var stripe = Stripe('pk_test_CscsJfPdlaNBpLla09y0aA6W', {
stripeAccount: '{{CONNECTED_STRIPE_ACCOUNT_ID}}'
});
stripe.redirectToCheckout({
// Make the id field from the Checkout Session creation API response
// available to this file, so you can provide it as parameter here
// instead of the {{CHECKOUT_SESSION_ID}} placeholder.
sessionId: '{{CHECKOUT_SESSION_ID}}'
}).then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
});
I've also got a Charges Controller, but I'm not sure if this is meant to be there:
session = Stripe::Checkout::Session.create({
payment_method_types: ['card'],
line_items: [{
name: "Cucumber from Roger's Farm",
amount: 200,
currency: 'gbp',
quantity: 10,
}],
payment_intent_data: {
application_fee_amount: 200,
},
success_url: 'https://example.com/success',
cancel_url: 'https://example.com/cancel',
}, {stripe_account: '{{CONNECTED_STRIPE_ACCOUNT_ID}}'})
How do I Initialize Stripe.js with the right account ID? Where is this code meant to be? Do I need more?
Any help would be massively appreciated. Thanks.

Transfer money from stripe account to other account

I'm using this to charge a connected account the send the money to another account but I keep getting this error message.
I keep getting this error message:
You cannot supply a destination when charging a connected account.
return stripe.charges.create({
amount: 1000,
currency: "usd",
source: customer_id,
destination: {
account: "acct_1BxnsfGGXo2wovzm"
},
});
How can I do it? Thanks
Looking at the error message it seems the api believes you're using account debits where the destination parameter does not make sense:
https://stripe.com/docs/connect/account-debits
So it's likely that your customer_id variable contains an account id instead of a customer id here.

Paypal recurring payments with variable amount 2 (in Spain)

some days ago, I wrote this post regarding Paypal recurring payments with variable amount Paypal recurring payments with variable amount
I marked it as fixed, however it is not.
First, I decided to develop approach 1 (by removing old profile and creating a new one). This worked. But, after that I realized, that I didn´t cover all my requirements. So finally, the right approach for me is number 2. This means, as #Andrew Angell suggested, I will develop a custom billing system that bills the customers. For that, I will create Billing Agreements and I will use the returned ids to execute Reference transactions with the amount I need and whenever I need. So far, it´s right?
According to Paypal docs, this is possible: https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECReferenceTxns/
So, I´m trying to follow the steps, so first a execute a setExpressCheckout:
# Paypal setExpressCheckout
def setExpressCheckout(billingType, returnURL, cancelURL, price, description)
#api = PayPal::SDK::Merchant::API.new
if billingType == "credit-card"
billingType = "Billing"
else
billingType = "Login"
end
#set_express_checkout = #api.build_set_express_checkout({
SetExpressCheckoutRequestDetails: {
ReturnURL: returnURL,
CancelURL: cancelURL,
LocaleCode: "US",
LandingPage: billingType,
PaymentDetails: [{
NotifyURL: returnURL,
OrderTotal: {
currencyID: "EUR",
value: price
},
ShippingTotal: {
currencyID: "EUR",
value: "0"
},
TaxTotal: {
currencyID: "EUR",
value: "0"
},
PaymentDetailsItem: [{
Name: description,
Quantity: 1,
Amount: {
currencyID: "EUR",
value: price
},
}],
PaymentAction: "Authorization" # To authorize and retain the funds, and when booking is confirmed capture them.
}],
BillingAgreementDetails: [{
BillingType: "MerchantInitiatedBillingSingleAgreement",
BillingAgreementDescription: description
}]
}
})
# Make API call & get response
#express_checkout_response = #api.set_express_checkout(#set_express_checkout)
# Access Response
if #express_checkout_response.success?
#token = #express_checkout_response.Token
puts "setExpressCheckout completed OK :)"
#paypal_url = #api.express_checkout_url(#express_checkout_response)
else
puts "setExpressCheckout KO :("
#express_checkout_response.Errors
puts "#express_checkout_response=" + #express_checkout_response.inspect
end
#express_checkout_response
end
However, I get this error:
#LongMessage="Merchant not enabled for reference transactions", #ErrorCode="11452"
It´s quite clear, just need to contact Paypal support guys and ask them to enable Reference transactions in my Paypal sandbox account. Right? I already did it and I´m just waiting.
However, what really worries me, is that I called Paypal support and they told me that this approach will not work in Spain. Although it´s in the doc, it´s only working in UK. Is this true?
If it´s true, I´m really in a trouble, because as far as I know, Paypal doesn´t not support subscriptions with variable amount.
Paypal technical support guy has enabled my sandbox account to reference transactions. I have developed the logic and it´s working. At least, in Sandbox and in Spain.
So, I will assume, it works.
Bad the Paypal guy on the phone that told me it wasn´t possible.

Returning a custom field where value depends on the query in elasticsearch

I have some data like so in elasticsearch:
account (http://localhost:9200/myapp/account/1)
========
name
state
groups //groups is an array containing objects like so {id: 1, starred: true}
//the id is the id of the group type
email (http://localhost:9200/myapp/email/1?parent=1)
========
email
primary //just a boolean to denote whether this email is primary or not
group
========
name
description
emails are children of account.
Based on imotov's excellent answer, I am able to run a search on account.name and email.email and return ALL accounts where the searched prefix matches the above 2 fields:
{
"query": {
"bool": {
"must": [
{
"term": {
"statuses": "active"
}
}
],
"should": [
{
"prefix": {
"name": "a"
}
},
{
"has_child": {
"type": "email",
"query": {
"prefix": {
"email": "a"
}
}
}
}
],
"minimum_number_should_match" : 1
}
}
}
What I would like to do now is to return 2 custom fields for each result:
For each result return a field called email, if the search was matched on the email type (which is a child of account), return that email, otherwise return the primary email linked to the account, if none, null can be returned.
For each result return a field called group. The value of the field should contain the name of the starred group whose id is stored in the groups array. Essentially: Find group.id where group.starred is true in each account.groups, then return the matching group.name from the group type base on the id we found.
I have been looking at script fields, but I am not sure if it is able to return fields for each hit. I am also not sure if the above is actually accomplishable in ES.
Could someone provide some pointers as to whether this is possible and how to get started?
Currently, there is simply no way to get to access the data in a has_child or nested clause.
The only solution is to get some data, make some decisions on the client and then get more data.
Here's what I did to achieve it:
Run the query above and get back the data.
To deal with showing the match emails or the primary email (run on the email type):
{"query":
{"bool":{
"should":{
{
"prefix":{
"email" : "the query"
}
},
{
"terms":{
"_parent" : ["list", "of", "account", "ids"]
}
}
}
}
}
}
Base on the above query, we can get any email addresses that were matched by the search term. Remember to set the fields in the above query to include _parent.
We can then use array_diff() or a similiar function in languages other than PHP to diff the parent ids from above and and original query. This should then give us a list of accounts where no email was matched. Simply then send another request to get the primary emails for those accounts.
For the groups, send a query to type account and:
Constrain _id to the list of account ids.
Constrain group.starred to true.
This should get you a list of starred groups. To get more information (name etc), send a query to type group and:
Constrain _id to the group ids above.
Finally, do some client side processing to put it together so that it is easier for the next part of your program to use.

Resources