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

Viewed 276

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?

2 Answers

With the advice from Alex I was able to find the following solution:

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

  2. 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();
    }
    
  3. 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