Skip to content

Magento 2.4.1: Place order using stripe payment method through REST API

I am making the mobile app in andriod and IOS using Magento2 as backend. In our website we are using stripe payment method.
Now I am trying to place an order using stripe method.

I am using magento default API in order to place an order “http://XXXX.com/rest/V1/carts/36/order” (where 36 is my quote id). I checked many documents and they suggested to use following in body:

{
    "paymentMethod": {
    "method": "stripe_payments",
        "additional_data" : {
        "cc_save" : false,
        "cc_stripejs_token" : "pm_card_visa:visa:4242"
        }
    }
}

By using above in body order is placed successfully and I got the order id in response. But now I am trying to make “cc_stripejs_token” from request received from app team. They have following information:

 card =     {
        brand = Visa;
        country = US;
        "cvc_check" = unchecked;
        "exp_month" = 8;
        "exp_year" = 2023;
        funding = credit;
        id = "card_1ImFqhGpA1zE4WUlvS12Hl9m";
        last4 = 4242;
        name = test;
        object = card;
    };
    "client_ip" = "132.154.98.207";
    created = 1619864099;
    id = "tok_1ImFqhGpA1zE4WUl3Eg9UFpA";
    livemode = 0;
    object = token;
    type = card;
    used = 0;
}

Now I am trying to make “cc_stripejs_token” by using this formula:

token.id + ':' + token.card.brand + ':' + token.card.last4 

My body looks like

{
           "paymentMethod": {
            "method": "stripe_payments",
             "additional_data" : {
                "cc_save" : false,
                "cc_stripejs_token" : "tok_1ImFqhGpA1zE4WUl3Eg9UFpA:visa:4242"
             }
        }
   
}

But I am getting error “TypeError: Return value of
MagentoInventorySalesPluginSalesOrderManagementAppendReservationsAfterOrderPlacementPlugin::aroundPlace() must
implement interface MagentoSalesApiDataOrderInterface.

I also tried by placing order using stripe intent method.

       StripeStripe::setApiKey('MY SECRET KEY');
        $st_response = StripeToken::create(array(
                    "card" => array(
                        "number" => "4242424242424242",
                        "exp_month" => 1,
                        "exp_year" => 2024,
                        "cvc" => "314"
                    )
        ));
       echo json_encode($st_response);         
       $charge = StripeCharge::create(array('amount' => 1000, 'currency' => "eur", 'source' => $st_response['id']));
      //echo json_encode($charge); 
      $tokenCard = $st_response['id'] . ':' . $charge['payment_method_details']['card']['brand'] . ':' . $charge['payment_method_details']['card']['last4'];

Payment is successful as I can see entries in Stripe dashboard but when trying to place an order using $tokenCard then it again shows error.

Please help me how can I place an order.