Stripe SCA checkout in ruby on rails - 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

Related

Passing report level filter to power bi from asp.net mvc application

I have embedded power bi report in my asp.net mvc application. It is working fine and it is showing data. I am having one issue, in my application every client has few branches like cities. Every user for that client may have access to all or some branches and based on that access we show data when that user is logged into system.
I want to achieve same in power bi that when user is logged into system and view reports it should show him/her data of branch he/she has access to. I found one solution
[Can I pass a dynamic query parameter to an embedded Power BI report in ASP.Net MVC? where we can set filter values from program side. I applied this in my view but i am still getting all data.
const branchFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "tblWorkhistory",
column: "BranchID"
},
operator: "In",
values: [1],
filterType: models.FilterType.BasicFilter
}
var config = {
type: 'report',
tokenType: models.TokenType.Embed,
accessToken: accessToken,
embedUrl: embedUrl,
id: embedReportId,
permissions: models.Permissions.All,
viewMode: models.ViewMode.View,
filters: [branchFilter],
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true
}
};
Here i want to apply filter where it will show data for only branch whose id is 1 but it is showing all data. Am i missing anything here? do i need to do anything report side also after this code?
Regards,
Savan
Applying filter using embed config is supported, and the code sample you've shared seems valid.
If report.setFilters fails as well, seems like something with the filter is wrong.
Try to verify the data type of the filter, should it be 1 or "1"?
If this doesn't work, is there any error message being returned from .setFilters request?:
const filter = { ... };
report.setFilters([filter])
.catch(errors => {
// Handle error
});
Learn more here about setting filters through JS SDK.
To show data based on the user logged into you application you have to apply Row Level Security (RLS) in your power bi report first and then follow the steps from following article https://learn.microsoft.com/en-us/power-bi/developer/embedded-row-level-security

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

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).

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

Quickbooks Online - Cannot get LinkedTxn detail

I created an Expense record and linked to an Invoice. When i import Invoice object through API, it has linked transaction as below.
"LinkedTxn":[{
"TxnId":"1356", //Id of Expense
"TxnType":"ReimburseCharge" //Type showing as ReimburseCharge
}]
In Quickbooks online docs, it is mentiond as
Links to expenses incurred on behalf of the customer are returned in
the response with LinkedTxn.TxnType set to ReimbCharge, ChargeCredit
or StatementCharge corresponding to billable customer expenses of type
Cash, Delayed Credit, and Delayed Charge, respectively. Links to these
types of transactions are established within the QuickBooks UI, only,
and are available as read-only at the API level.
Use LinkedTxn.TxnLineId as the ID in a separate read request for the
specific resource to retrieve details of the linked object.
In response it is showing TxnType as ReimburseCharge, but I didn't see any object like that in api explorer or docs. I don't know what type of object to request with id. I tried with Purchase, PurchaseOrder, Bill etc. but not of the request returned expected expense record.
Please help on how to access this Expense record with linked transaction id through api.
Invoice JSON:
Invoice line with description Printing paper is the expense linked in this invoice.
{
"Invoice":{
"Id":"1358",
"LinkedTxn":[
{
"TxnId":"1356",
"TxnType":"ReimburseCharge"
}
],
"Line":[
{
"Id":"1",
"LineNum":1,
"Description":"Printing paper",
"DetailType":"DescriptionOnly",
"DescriptionLineDetail":{
}
},
{
"Id":"3",
"LineNum":2,
"Description":"Magazine Monthly",
"Amount":100.0,
"DetailType":"SalesItemLineDetail",
"SalesItemLineDetail":{
"ItemRef":{
"value":"19",
"name":"Publications:Magazine Monthly"
},
"UnitPrice":100,
"Qty":1,
"TaxCodeRef":{
"value":"NON"
}
}
},
{
"Amount":250.0,
"DetailType":"SubTotalLineDetail",
"SubTotalLineDetail":{
}
}
],
"Balance":250.0
}
}
The docs are a little confusing on this point - unfortunately, the second paragraph
Use LinkedTxn.TxnLineId as the ID in a separate read request for the specific resource to retrieve details of the linked object.
is a generic paragraph that appears for docs on every Ref type, but shouldn't appear here. It's impossible to access these transactions via the API. More detail available here.

Integration tests create test users on Stripe, how to stop or stub out

I'm using stripe on a project. I'm using Railscasts #288 (http://railscasts.com/episodes/288-billing-with-stripe) as a guide. I have it so that once a user registers with a valid username and password I will create their Stripe customer account.
After a few runs of my integration test I can see that I have many users created in my test account for Stripe. How do I structure the integration test so that it goes through my registration process as a typical user would, but without creating the Stripe account with Stripe?
I'm coming a little late to the game, but check out StripeMock. It is made specifically for this purpose.
StripeMock.start
Stripe::Customer.create({
id: '123',
email: 'someone#something.com',
card: 'void_card_token',
subscriptions: {
data: [{
plan: {
name: 'Some Subscription Plan',
currency: 'usd',
amount: 1000
},
start: 1410408211,
status: 'active',
current_period_start: 1410408211,
current_period_end: 1413000211
}]
}
})
test... test... test...
StripeMock.stop
i dealt with that by making all my customers created through the testing have "deletable" in their email address, and adding these lines to my spec_helper.
config.after(:suite) do
custs = Stripe::Customer.all(limit: 100).data
custs.keep_if { |c| c.email.match( /deletable/ ) }
custs.each { |c| c.delete }
end
This is typically done with a tool like WebMock which intercepts the HTTP request and returns a response you provide. The VCR gem makes this process easier by recording and replaying HTTP requests using WebMock (or optionally FakeWeb) under the hood. There is a Railscast on VCR, but it is a bit out of date. Take care not to record any sensitive data (i.e. api keys) by using the filter_sensitive_data configuration option.
It's difficult to really test an integration without making your tests as realistic as possible. Therefore, I suggest that you let stripe create the test customer accounts, but make use of the webhooks to automatically delete them.
Specifically, you would handle the customer.created event. If event->livemode == false, send a request back to the api to delete the customer.
This way, you run through the entire process as you test, while only keeping customers that were created in live mode.

Resources