How to set payment details with store-api in shopware 6 - stripe-payments

i want to use shopware as a headless shop with stripe payment provider. The payment works in shopware without problems.
Now im testing the order steps with api only. the last step is to handle the payment through the provider (stripe in this case).
in the shopware documentation its handled with the api call /store-api/handle-payment.
the payload looks like this:
{
"orderId": "string",
"finishUrl": "string",
"errorUrl": "string"
}
now when i request the api i get 500 error with message:
No credit card selected
My question is, how to send credit card data through this api so that Stripe can handle the payment. Is there anyone to solved this problem?

With the advice from Alex I was able to find the following solution:
Find error credit card not selected: This happens only when you try to pay per api request. The reason i found was, that Stripe saves the payment details (credit card id) in the session object. Per api you have no access to this as default and thatswhy u get the message credit card not selected
Take a look at the stripe plugin, especially in your PaymentMethods/Card/CardPaymentConfigurator.
i put the following in the configure method
from Line 46 - 62
$requestDataBag = $stripePaymentContext;
$paymentDetails = $requestDataBag->requestDataBag->get('paymentDetails');
if(!null == $paymentDetails) {
$card = $paymentDetails->get('creditCardId');
} else {
$card = null;
}
$selectedCard = $this->stripePaymentMethodSettings->getSelectedCard();
if ($selectedCard || isset($selectedCard['id'])) {
$selectedCard = $selectedCard['id'];
} elseif ($card) {
$selectedCard = $card;
} else {
throw PaymentIntentPaymentConfiguratorException::noCreditCardSelected();
}
send payment data per handle-payment request:
let payload = {
"orderId": event,
"finishUrl": "https://www.myfinishurl.de",
"errorUrl": "https://www.myurl.de/order/error",
"paymentDetails": {
"creditCardId": "creditcardid"
}
Now do this for all methods you need. It works. Maybe Stripe can implement this in the future.

You have the following options:
Check the local API documentation - it might have more information than the public one, because it honors installed modules (see https://stackoverflow.com/a/67649883/288568)
Contact their support for more information as this is not covered in the API Docs
Make a test-payment via the normal storefront and look at the requests which are made in the network panel of your browser's development tools

Related

Incomplete API response for getUsers

I'm implementing an API integration for DocuSign, and I'm currently hitting the following endpoint: /v2/organizations/{organizationId}/users
The documentaton for this: https://developers.docusign.com/docs/admin-api/reference/users/users/getusers/#response200_docusign.api.organizations.web.models.restapi.v2.response.organizationuserresponse
The documentation is showing a response field, user_status. However, when I call the API, I get a response as follows:
{
"users":[
{
"id":"xxx-xxx-xxx-xxx-xxx",
"user_name":"Xxxx",
"first_name":"",
"last_name":"Xxxx",
"membership_status":"active",
"email":"xxxx#gmail.com",
"membership_created_on":"2021-07-30T02:24:20.243",
"membership_id":"xxxx-xxxx-xxxx-xxxx-xxxx"
},
{
"id":"yyy-yyy-yyy-yyy-yyy",
"user_name":"Yyyyy",
"first_name":"Yyyyy",
"last_name":"2",
"membership_status":"active",
"email":"yyyyyyy#yyy.yyy",
"membership_created_on":"2021-07-30T02:26:59.313",
"membership_id":"yyy-yyy-yyy-yyy-yyy"
},
{
"id":"zzz-zzz-zzz-zzz-zzz",
"user_name":"Zzzzz",
"first_name":"Zzzz",
"last_name":"Zzzz",
"membership_status":"active",
"email":"zzz#zzz-zzz.net",
"membership_created_on":"2021-07-15T04:05:18.803",
"membership_id":"zzz-zzz-zzz-zzz-zzz"
}
],
"paging":{
"result_set_size":3,
"result_set_start_position":0,
"result_set_end_position":2,
"total_set_size":3
}
}
As you can see, we have no user_status. Do we need to send any request parameters, to expand the response, or has this field been removed from the API response without being updated on the API documentation?
Or, could I assume that the user is active, if it appears in the API response, with a membership_status of active?
Thank you very much!
membership_status is probably what you're looking for.
there's no such thing as user_status because a user can be a member of multiple accounts and each membership can have a different status.
Here is a useful diagram:

Get Receipt number on Stripe C#

Please how can I get the receipt number on Stripe with c#
My image :
https://www.casimages.com/i/191231053006538388.png.html
Maybe with a Session ID ?
You'd access the Charge object and it's a field on that resource.
You say you're using Checkout. So the Charge is under session.payment_intent.charges.data[0]. It requires a little digging to get it but it's all there. I'd suggest that when you receive the event as part of fulfilling the order etc, retrieve the Session(stripe.com/docs/api/checkout/sessions/retrieve) and expand "payment_intent". Then session.PaymentIntent.Charges.Data[0].ReceiptNumber is the value you're looking for.
static void CheckoutSessionReceiptEmail()
{
var service = new Stripe.Checkout.SessionService();
var session = service.Get(
"cs_test_nHUZtpUvaI80YAKGgCMGyeHfjQ6nMtUhVLeVpowWsgpfyGujccGxnAuJ",
new Stripe.Checkout.SessionGetOptions
{
Expand = new List<string> { "payment_intent" }
}
);
Console.WriteLine(session.PaymentIntent.Charges.Data[0].ReceiptNumber);
}

How to get PaymentIntent next_action.type = redirect_to_url instead of use_stripe_sdk for Subscription

I am working on the implementing Subscription*(which is SCA ready) using Stripe.
I try to handle https://stripe.com/docs/billing/subscriptions/payment#handling-action-required.
After the subscription is created on Stripe side, I have got the answer like in documentation above:
{
"id": "sub_XXXXXXXXXXXXXXXXXXX",
"object": "subscription",
"status": "incomplete",
...
"latest_invoice": {
...
"payment_intent": {
"status": "requires_action",
...
"next_action": {
"type": "use_stripe_sdk",
...
},
...
}
}
}
According to the documentation https://stripe.com/docs/api/payment_intents/object#payment_intent_object-next_action-type
next_action.type can have two values redirect_to_url and use_stripe_sdk
So my question is how to get next_action.type = redirect_to_url(instead of use_stripe_sdk) and how to force stripe to fill next_action.redirect_to_url(Because I want to handle it on my own in my UI)?
*There is already a similar question on SO:
https://stackoverflow.com/questions/56490033/how-to-handle-use-stripe-sdk-through-php
but my case is to create Subscription where I don't have control over PaymentIntent
In my understanding, the next_action.type will be equal to redirect_to_url only if you choose to manually handle 3D Secure authentication https://stripe.com/docs/payments/payment-intents/verifying-status#manual-3ds-auth
As per documentation:
To handle 3D Secure authentication manually, you can redirect the customer. This approach is used when you manually confirm the PaymentIntent and provide a return_url destination to indicate where the customer should be sent once authentication is complete. Manual PaymentIntent confirmation can be performed on the server or on the client with Stripe.js.
Example using Stripe.js:
stripe.confirmPaymentIntent(
'{PAYMENT_INTENT_CLIENT_SECRET}',
{
payment_method: '{PAYMENT_METHOD_ID}',
return_url: 'https://example.com/return_url'
}
).then(function(result) {
// Handle result.error or result.paymentIntent
});
Example using Stripe Python:
intent = stripe.PaymentIntent.confirm(
'{PAYMENT_INTENT_ID}',
payment_method='{PAYMENT_METHOD_ID}',
return_url='https://example.com/return_url'
)
EDIT: as per #karllekko's comment the {PAYMENT_INTENT_ID} will in your case be latest_invoice.payment_intent.id.
Please read https://stripe.com/docs/payments/3d-secure-iframe - it gives more details about the "return_url" flow - and describes also posibilities to customize it inside "iframe" etc
Probably this document is fairly recent - so at the time of this question (July) it was not existing yet

How to get more customer sources using Stripe NodeJS SDK?

I am able to get customer sources only 1st 10 via get customer API:
# stripe.customers.retrieve
{
"id": "cus_DE8HSMZ75l2Dgo",
...
"sources": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_DE8HSMZ75l2Dgo/sources"
},
...
}
But how do I get more? Is the only way via an AJAX call? I was thinking there should be a function somewhere in the SDK?
When you retrieve a Customer object via the API, Stripe will return the sources property which is a List object. The data property will be an array with up to 10 sources in it.
If you want the ability to get more sources than the 10 most recent ones, you will need to use Pagination. The idea is that you will first get a list of N objects (10 by default). Then you will request the next "page" from Stripe by asking for N objects again but using the parameter starting_after set to the id of the last object in the previous page. You will continue doing that until the has_more property in the page returned is false indicating you retrieved all the objects.
For example if your Customer has 35 sources, you would get the first page (10), then call list to get 10 more (20), then 10 more again (30) and then the last call would return only 5 sources (35) and has_more would be false.
To decrease the number of calls, you can also set limit to a higher value. The maximum value is 100 in that case.
Here's what the code would look like:
// list those cards 3 at a time
var listOptions = {limit: 3};
while(1) {
var sources = await stripe.customers.listSources(
customer.id,
listOptions
);
var nbSourcesRetrieved = sources.data.length;
var lastSourceId = sources.data[nbSourcesRetrieved - 1].id;
console.log("Received " + nbSourcesRetrieved + " - last source: " + lastSourceId + " - has_more: " + sources.has_more);
// Leave if we are done with pagination
if(sources.has_more == false) {
break;
}
// Store the last source id in the options for the next page
listOptions['starting_after'] = lastSourceId;
}
You can see a full running example on Runkit here: https://runkit.com/5a6b26c0e3908200129fbb5d/5b49eabda462940012c33880
Taking a quick look into the sources of the stripe-node package, it seems there is a stripe.customers.listSources method, which takes a customerId as parameter and requests to the correct url. I suppose it works similar to the listCards method. But I couldn't find it in the docs, so you have to treat it as an undocumented feature ... But maybe it's just an error in the docs. You could contact the support about it. We used stripe in an old project and they appreciated any input on their documentation.
As of stripe-node 6.11.0, you may auto-paginate list methods, including customer sources. Stripe provides a few different APIs for this to aid with a variety of node versions and styles.
See the docs here
The important part to notice is .autoPagingEach:
await stripe.customers.listSources({ limit: 100 }).autoPagingEach(async (source) => {
doSomethingWithYourSource(source)
})

how to get "my pull requests" from github api?

If you look at: http://developer.github.com/v3/pulls/ it shows you how to get pull requests for a given repository.
How do we get "my pull requests" from the GitHub API similar to the data displayed on the GitHub dashboard?
I asked Github directly. A rep told me to use the search endpoint. Search for issues owned by you that are open and of type pr.
https://api.github.com/search/issues?q=state%3Aopen+author%3Adavidxia+type%3Apr
If you're using a python client lib like Pygithub you can do
issues = gh.search_issues('', state='open', author='davidxia', type='pr')
You can also use GraphQL API v4 to get all your pull requests :
{
user(login: "bertrandmartel") {
pullRequests(first: 100, states: OPEN) {
totalCount
nodes {
createdAt
number
title
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
Try it in the explorer
or using viewer :
{
viewer {
pullRequests(first: 100, states: OPEN) {
totalCount
nodes {
createdAt
number
title
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
First you have to realize that you must authenticate using either Basic Authentication or a token. Next you have to realize that there is no simple way to do this so you will have to be clever.
To be specific, if you probe https://api.github.com/issues, you'll notice that the issues there have a hash called pull_request which should have 3 URLs: html, diff, and patch. All three will be non-null if the issue is also a Pull Request. (Pro-tip: They're the same thing as far as GitHub is concerned…sort of.)
If you iterate over your issues and filter for ones where those attributes are not null, then you'll have your pull requests.

Resources