How to pass the card details for the Magento API [POST]: V1/carts/mine/payment-information for the payment method stripe_payments_checkout_card

magento.stackexchange https://magento.stackexchange.com/questions/326987

Question

I have an iOS native app which communicates through Magento Rest APIs with my Magento Store, I would like to know how to pass the card details (Token, CVV, Exp Year, Exp Month, Last 4) in JSON format for the payment method "method":"stripe_payments_checkout_card" in the Magento API: [POST] V1/carts/mine/payment-information

Note: I use the Stripe Official Module:https://marketplace.magento.com/stripe-stripe-payments.html The process is a follow:

1. [POST] V1/integration/customer/token  
   [Body]: 
   {
     "username": "jdoe@example.com",
     "password": "Password1"
   }
   [Repons]: "eg5d7l5n76gkbi192x53d3gjzgndtx54"

2.[POST] V1/carts/mine
  [Bearer Token] "eg5d7l5n76gkbi192x53d3gjzgndtx54"
  [Repons]: 7470

3.[POST] V1/carts/mine/items
  [Bearer Token] "eg5d7l5n76gkbi192x53d3gjzgndtx54"
  [Body]:
  {
    "cartItem": {
      "sku": "Abc-1032",
      "qty": 1,
      "quote_id": "7470"
    }
  }
  [Respons]:
  {
      "item_id": 2494,
      "sku": "Abc-1032",
      "qty": 1,
      "name": "Rug",
      "price": 635,
      "product_type": "simple",
      "quote_id": "7470"
  }

5. [POST] V1/carts/mine/estimate-shipping-methods
[Bearer Token] "eg5d7l5n76gkbi192x53d3gjzgndtx54" 
[Body]:
{
  "address": {
    "region": "New York",
    "region_id": 43,
    "region_code": "NY",
    "country_id": "US",
    "street": [
      "123 Oak Ave"
    ],
    "postcode": "10577",
    "city": "Purchase",
    "firstname": "Jane",
    "lastname": "Doe",
    "customer_id": 6272,
    "email": "jdoe@example.com",
    "telephone": "(512) 555-1111",
    "same_as_billing": 1
  }
}
[Respons]:
[
    {
        "carrier_code": "flatrate1",
        "method_code": "flatrate1",
        "carrier_title": "Flat Rate",
        "method_title": "Fixed",
        "amount": 15,
        "base_amount": 15,
        "available": true,
        "error_message": "",
        "price_excl_tax": 15,
        "price_incl_tax": 15
    }
]

6. [POST] V1/carts/mine/shipping-information  
[Bearer Token] "eg5d7l5n76gkbi192x53d3gjzgndtx54"  
[Body]:
{
  "addressInformation": {
    "shipping_address": {
      "region": "New York",
      "region_id": 43,
      "region_code": "NY",
      "country_id": "US",
      "street": [
        "123 Oak Ave"
      ],
      "postcode": "10577",
      "city": "Purchase",
      "firstname": "Jane",
      "lastname": "Doe",
      "email": "jdoe@example.com",
      "telephone": "512-555-1111"
    },
    "billing_address": {
      "region": "New York",
      "region_id": 43,
      "region_code": "NY",
      "country_id": "US",
      "street": [
        "123 Oak Ave"
      ],
      "postcode": "10577",
      "city": "Purchase",
      "firstname": "Jane",
      "lastname": "Doe",
      "email": "jdoe@example.com",
      "telephone": "512-555-1111"
    },
    "shipping_carrier_code": "flatrate1",
    "shipping_method_code": "flatrate1"
  }
}
[Respons]:
{
    "payment_methods": [
        {
            "code": "paypal_express_bml",
            "title": "PayPal Credit (Paypal Express Bml)"
        },
        {
            "code": "paypal_express",
            "title": "PayPal Express Checkout"
        },
        {
            "code": "stripe_payments_checkout_card",
            "title": "Pay by Card (Stripe)"
        }
    ],
    "totals": {
        "grand_total": 650,
        "base_grand_total": 650,
        "subtotal": 635,
        "base_subtotal": 635,
        "discount_amount": 0,
        "base_discount_amount": 0,
        "subtotal_with_discount": 635,
        "base_subtotal_with_discount": 635,
        "shipping_amount": 15,
        "base_shipping_amount": 15,
        "shipping_discount_amount": 0,
        "base_shipping_discount_amount": 0,
        "tax_amount": 0,
        "base_tax_amount": 0,
        "weee_tax_applied_amount": null,
        "shipping_tax_amount": 0,
        "base_shipping_tax_amount": 0,
        "subtotal_incl_tax": 635,
        "shipping_incl_tax": 15,
        "base_shipping_incl_tax": 15,
        "base_currency_code": "USD",
        "quote_currency_code": "USD",
        "items_qty": 1,
        "items": [
            {
                "item_id": 2494,
                "price": 635,
                "base_price": 635,
                "qty": 1,
                "row_total": 635,
                "base_row_total": 635,
                "row_total_with_discount": 0,
                "tax_amount": 0,
                "base_tax_amount": 0,
                "tax_percent": 0,
                "discount_amount": 0,
                "base_discount_amount": 0,
                "discount_percent": 0,
                "price_incl_tax": 635,
                "base_price_incl_tax": 635,
                "row_total_incl_tax": 635,
                "base_row_total_incl_tax": 635,
                "options": "[]",
                "weee_tax_applied_amount": null,
                "weee_tax_applied": null,
                "name": "Rug"
            }
        ],
        "total_segments": [
            {
                "code": "subtotal",
                "title": "Subtotal",
                "value": 635
            },
            {
                "code": "shipping",
                "title": "Shipping & Handling (Flat Rate - Fixed)",
                "value": 15
            },
            {
                "code": "tax",
                "title": "Tax",
                "value": 0,
                "area": "taxes",
                "extension_attributes": {
                    "tax_grandtotal_details": []
                }
            },
            {
                "code": "grand_total",
                "title": "Grand Total",
                "value": 650,
                "area": "footer"
            }
        ]
    }
}

7. [POST] V1/carts/mine/payment-information
[Bearer Token] "eg5d7l5n76gkbi192x53d3gjzgndtx54"  
[Body]:
{
    "paymentMethod": {
        "method": "stripe_payments_checkout_card"
    },
    "billing_address": {
        "email": "jdoe@example.com",
        "region": "New York",
        "region_id": 43,
        "region_code": "NY",
        "country_id": "US",
        "street": ["123 Oak Ave"],
        "postcode": "10577",
        "city": "Purchase",
        "telephone": "512-555-1111",
        "firstname": "Jane",
        "lastname": "Doe"
    }
}
Was it helpful?

Solution

Stripe Checkout is a redirect-based payment method. This means that card details are collected at the Stripe hosted payment page, not in your iOS app. The collection and tokenization of the card details will be handled by Stripe at the payment page. The tokenized card token, if you need to use if for post-processing actions, can be collected through the charge.succeeded webhook that arrives back to Magento after the payment.

What your iOS app needs to do though, is to redirect the customer to the Stripe hosted payment page. See the placeOrder() method on line 90 of view/frontend/web/js/view/payment/method-renderer/method.js on how to perform the redirect.

For the actual implementation of the redirect, see line 30 of view/frontend/web/js/view/payment/method-renderer/checkout/card.js

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top