How to resolve "Stripe::InvalidRequestError, No such customer 'cus_XYZ....'" error for invoicing? - ruby-on-rails

Just ran into a weird error I cannot seem to resolve. I am trying to send a one-off invoice to some of my Stripe customers. I have stored their customer id's on the server side, however each time I create a one-off invoice, I get the "No such customer error".
I have hard-coded their id's on the server side and Stripe will then say it will bill the supplier (it won't send the email however). When I manually create an invoice in the Stripe Dashboard everything works fine.
Stripe::InvoiceItem.create({
customer: stripe_supplier.to_s,
amount: 1000,
currency: 'usd',
description: 'Order fee from LocalVore!',
})
invoice = Stripe::Invoice.create({
customer: stripe_supplier.to_s,
billing: "send_invoice",
days_until_due: 10,
})
invoice.send_invoice
When I hit call this (from a parent function, of course) Stripe will say that the customer does not exist (parameter is stripe_supplier which represents our customer id).

Related

How to update a customer belonging to a connected account in Stripe?

I am building a Rails 5.2 app. In this app I have integrated Stripe Connect.
I am currently building a feature where my customers can enroll their customers in subscriptions. The front end is Angular 11.
After the user have entered their payment data I need to attach this payment method to the created customer but I am not able too.
When I use this code it says that the customer is not found (even though I am using the correct ID). I guess it's because I created the Customer to a connected account.
The problem is I have no way of setting the stripe_account ID to the code.
customer = Stripe::Customer.update(
params[:customer],
invoice_settings: {
default_payment_method: params[:payment_method_id]
}
)
If I try this it says the stripe_account parameter is not valid.
"(Status 400) (Request req_sByQlJONJi0oHt) Received unknown parameter: stripe_account"
customer = Stripe::Customer.update(
params[:customer],
invoice_settings: {
default_payment_method: params[:payment_method_id]
}, stripe_account: params[:account]
)
So basically, how can I update a customer belonging to a Connected Account?
The update definition looks like this:
def update(id, params = {}, opts = {})
So in your case, the stripe_account is being passed in the params argument instead of the opts argument. Wrap the params in brackets ({}).
customer = Stripe::Customer.update(params[:customer],
{invoice_settings: {default_payment_method: params[:payment_method_id]}},
{stripe_account: params[:account]})

Stripe SCA checkout in ruby on rails

I am trying to update a monolithic rails stripe form to be SCA complaint, this is the documentation I am following https://stripe.com/docs/payments/checkout/migration#api-products-afterenter image description here
but is give in me error, invalid parameter, the error is in the picture, enter image description here
this is my code
const stripe = Stripe('pk_test_BqQVTnHd7yKaGgzUK9q8m8Ub00');
let checkoutButton = document.querySelector('#checkout-button');
checkoutButton.addEventListener('click', function () {
stripe.redirectToCheckout({
items: [{
// Define the product and SKU in the Dashboard first, and use the SKU
name: 'onex',
// ID in your client-side code.
id: 1,
parent: 'sku_Ft94t7sJmbJHlY',
sku: 'sku_123',
quantity: 1
}],
successUrl: 'https://www.example.com/success',
cancelUrl: 'https://www.example.com/cancel'
});
});
and I created a product in stripe dashboard
enter code here
enter image description here
According to Stripe's documentation, the only properties you can pass into the items list of stripe.redirectToCheckout are sku, plan, and quantity.
https://stripe.com/docs/stripe-js/reference#stripe-redirect-to-checkout
So in this case, the name, id, and parent properties are invalid. The "client-side" checkout integration is made to be pretty simplistic, where you create the SKU in the dashboard and simply include it in your JS.
If you need more control, I'd recommend looking at their server-side integration, which involves creating a Checkout Session.
https://stripe.com/docs/payments/checkout/server#create-checkout-session

How to use Order id in square-connect payment gateway in asp.net

I use this code, this is working done payment when I remove OrderId: "21071" this, but I want to use OrderId: "21071" this is "21071" my website order id that customer place order from my website.
ChargeRequest body = new ChargeRequest(AmountMoney: amount, IdempotencyKey: uuid, CardNonce: nonce, BillingAddress: address, ShippingAddress: address, BuyerEmailAddress: txtEmail.Text, ReferenceId: "Booking #:" + bookingid, Note: bookingid, OrderId: "21071");
ChargeResponse response = transactionsApi.Charge(LocationId, body);
I face this error
Error calling Charge: {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"NOT_FOUND","detail":"Resource not found.","field":"order_id"}]}
My error occurs when I use Orderid without Orderid it works fine, but I want to use Orderid
It seems like you're using your own Order ID there, instead of creating an Order using the Orders API first, and then referencing that Order ID in your Transaction.
You can find an example of how to use the Square Orders API here: https://developer.squareup.com/docs/orders-api/cookbook/link-orders-and-catalog-item

"The token is invalid" when trying to setup Paypal recurring payments with ActiveMerchant

I feel like a lot of the documentation on this is outdated, but this is what I have been trying so far:
I am using the ActiveMerchant::Billing::PaypalExpressGateway gateway.
First I setup the purchase and redirect the user to Paypal:
response = gateway.setup_purchase price,
return_url: <confirm url>,
cancel_return_url: <cancel url>,
items: [
{
name: 'My Item',
quantity: 1,
description: "My Item Description",
amount: price
}
]
redirect_to gateway.redirect_url_for(response.token)
This works, I can sign in as a sandboxed buyer and confirm the payment, which brings me back to <confirm url> from above. In the confirmation, I do:
response = gateway.recurring price, nil,
token: params[:token],
period: 'Year',
frequency: 1,
start_date: Time.now,
description: 'My Item Subscription'
When I do this, I receive an invalid token error from Paypal in the response variable. The token seems to be fine, it is present in the URL when I am brought back to the confirmation URL. I'm then taking it directly (params[:token]) and sending it back to Paypal.
Am I doing something completely wrong? Like I said, it seems like a lot of the documentation for this type of process is outdated (or maybe what I am trying is the stuff that is outdated...)
After looking through the source code for ActiveMerchant's Paypal express checkout gateway, I came to the conclusion that it's simply outdated when dealing with recurring payments. I switched to the paypal-recurring gem instead and everything worked fine.

Balanced Payments - Balanced::BankAccount and invalidation of stored accounts

I am adding Balanced Payments (-v 0.6.0) to an existing system to enable marketplace features, and am running into an issues with the cleanup (invalidation) of a stored Bank Account when a new Bank Account is added/stored to a Customer Account (we only want sellers in marketplace to have at most one Bank Account active, to reduce complexity).
to make my question simple, here is a simple version of the what we are attempting, and the log response (error)
if (!params[:balanced_uri].blank?)
begin
#balanced_acctresponse = Balanced::Account.find(params[:balanced_uri])
bankaccts = Balanced::BankAccount.find(#balanced_acctresponse.bank_accounts_uri)
bankaccts.invalidate
rescue => e
logger.debug("Balanced Bank Account error :: #{e}")
end
this is generating the following exception
Balanced Bank Account error :: Balanced::BadRequest(400)::Bad
Request:: POST
https://api.balancedpayments.com/v1/marketplaces/xxxxxx/accounts/xxxxxx/bank_accounts?limit=10&offset=0:
request: Missing required field [name]
I'm confused as to what name field is missing. As defined here http://rubydoc.info/gems/balanced/0.6.0/Balanced/BankAccount there is no name param required for invalidate
I suggest you upgrade to the latest version of balanced-ruby (0.7.4). I recommend you then try something like:
begin
#account = Balanced::Account.find(current_user.balanced_account_uri)
#account.bank_accounts.each do |ba|
ba.invalidate
end
rescue => e
logger.debug("Balanced Bank Account error :: #{e}")
end
This will find the Account instance in Balanced, loop through its bank accounts and invalidate each of them.
NOTE: Account was deprecated about 9 months ago, superseded by Customer. Account will not be in the next API revision.
If you have any other questions, feel free to also drop by #balanced on Freenode IRC. There you can get assistance directly from developers.

Resources