Guest Cart Paypal Payment Steps: Magento 2 REST API

In this post, I am going to explain how to perform guest cart Paypal payment steps in Magento 2 application.

Paying an amount in the Magento 2 store through a guest customer account is essential or improves your customer experience.

Paying via PayPal Payments inside the Magento store is also an important part for guest customers.

Through this post, we will go to know how to add items inside cutout for any guest customer and save shipping information and how to do any payment.

 

Magento 2 Guest Cart PayPal Payment Steps

Checking out guest customers for the Magento website is required for mobile applications.

Through this post, we will tell the guest customer the steps to add an item cart through rest api then save shipping information inside it using rest API.

In the last step, the guest customer will make the payment via PayPal payment at the checkout page to make the payment using the REST API.

Then after the PayPal payment is completed, it will also show the massage of its response on the success page.

 

Read more: Configure PayPal in Magento 2 : How to Integrate PayPal

 

Step 1: Get Admin Access Token

In the first step, the admin will get the access token of the login, then in the second step, the access token will be used.

To get the access token we will send admin details of the Magento store ie admin user and password inside the body and in return, we will get an access token.

Endpoint:

https://wishusucess.com/rest/V1/integration/admin/token

Method: POST

Header: Not required

Get Admin Access Token

Response:

rw1y20up27hrzcu1l6lp4t6uitsnczag

 

Step 2: Create Empty Cart for The Guest Customer

Now using the admin access token we will create an empty card for the guest customer.

Then we will get a quote id for a guest card through this API as a response.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/

Method: POST

Header: Not required

Guest Cart PayPal Payment Steps

Response:

hQDMOwbCqcub25qSfQccL3bFLTsDGSaC

 

Step 3: Add or Update Items in Cart

The REST API we hit in the second step yielded a quote ID.

Quote ID will be used for Add to Cart Items or Update Items of Guest Cart of Guest Customer.

To add cart item, inside the body will send the quote id as well as product details like SKU item quantity, etc.

In the header, the admin token will also be sent for authorization.

Now we will hit the guest customer add to cart Rest API, after that, we will get the response and in that response, the item which we mentioned in the body will be added.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/w2CFwWlzAkhnym999IBdQl8LBp9r6sdE/items

Method: POST

Header:

  • Content-Type: application/json
  • Authorization: Bearer Admin_Token

Body: 

{ "cartItem": { "quote_id": "w2CFwWlzAkhnym999IBdQl8LBp9r6sdE", "sku": "accessories1231", "qty": 1 } }

Add Update Cart Item REST API

 

Step 4: Get The Cart Details

Now we will hit by adding the quote id to the end of the rest API. We will get the cart detail of the guest customer using this api.

In this detail, you will get the product name, price, item ID, product type, etc. by using this cart detail Magento 2 rest API.

Endpoint

https://wishusucess.com/index.php/rest/V1/guest-carts/ewWBDaATec0fKEo15lZkGzEiaoZ1p6sh

Method: GET

Header:

  • Content-Type: application/json
  • Authorization: Bearer Admin_Token

Body: 

Not required

Get the Cart Details REST API

Response:

{
"id": 2271,
"created_at": "2022-02-11 06:22:24",
"updated_at": "2022-02-11 06:24:47",
"is_active": true,
"is_virtual": false,
"items": [
{
"item_id": 1009,
"sku": "accessories1231",
"qty": 1,
"name": "accessories mono c",
"price": 133,
"product_type": "simple",
"quote_id": "2271",
"extension_attributes": {
"image_url": "https://wishusucess.com/pub/media/catalog/product/cache/54139b022fb7bb8c324a752eac907829/b/a/bags_9.png"
}
}
],
"items_count": 1,
"items_qty": 1,
"customer": {
"email": null,
"firstname": null,
"lastname": null
},
"billing_address": {
"id": 4706,
"region": null,
"region_id": null,
"region_code": null,
"country_id": null,
"street": [
""
],
"telephone": null,
"postcode": null,
"city": null,
"firstname": null,
"lastname": null,
"email": null,
"same_as_billing": 0,
"save_in_address_book": 0
},
"orig_order_id": 0,
"currency": {
"global_currency_code": "USD",
"base_currency_code": "USD",
"store_currency_code": "USD",
"quote_currency_code": "USD",
"store_to_base_rate": 0,
"store_to_quote_rate": 0,
"base_to_global_rate": 1,
"base_to_quote_rate": 1
},
"customer_is_guest": false,
"customer_note_notify": true,
"customer_tax_class_id": 3,
"store_id": 1,
"extension_attributes": {
"shipping_assignments": [
{
"shipping": {
"address": {
"id": 4707,
"region": null,
"region_id": null,
"region_code": null,
"country_id": null,
"street": [
""
],
"telephone": null,
"postcode": null,
"city": null,
"firstname": null,
"lastname": null,
"email": null,
"same_as_billing": 1,
"save_in_address_book": 0
},
"method": null
},
"items": [
{
"item_id": 1009,
"sku": "accessories1231",
"qty": 1,
"name": "accessories mono c",
"price": 133,
"product_type": "simple",
"quote_id": "2271",
"extension_attributes": {
"image_url": "https://wishusucess.com/pub/media/catalog/product/cache/54139b022fb7bb8c324a752eac907829/b/a/bags_9.png"
}
}
]
}
]
}
}

 

Step 5: Add Shipping Information to The Cart

Through this REST API, we will save the shipping address to which the product is to be delivered to the customer i.e. use this rectify to save the shipping address.

This REST API will serve to save the shipping address for the guest customer on the store.

When we will get the response, the payment methods available in the store will be shown in that response.

The kind of payment method that Magento store is providing will be visible as an available payment method response.

Now payment can be done by selecting that payment method in the next step.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/ewWBDaATec0fKEo15lZkGzEiaoZ1p6sh/shipping-information

Method: POST

Header:

  • Content-Type: application/json
  • Authorization: Bearer Admin_Token

Body: 

{
"addressInformation": {
"billingAddress": {
"region": "UP",
"region_id": 566,
"country_id": "IN",
"street": [
"Botanical Garden Metro, Noida"
],
"company": "Wishusucess",
"telephone": "1111111",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemamt",
"lastname": "Singh",
"email": "cs.hemantsingh@gmail.com",
"prefix": "address_",
"region_code": "UP"
},
"shippingAddress": {
"region": "UP",
"region_id": 566,
"country_id": "IN",
"street": [
"Botanical Garden Metro, Noida"
],
"company": "Wishusucess",
"telephone": "1111111",
"postcode": "201301",
"city": "Noida",
"firstname": "Hemant",
"lastname": "Singh",
"email": "cs.hemantsingh@gmail.com",
"prefix": "address_",
"region_code": "UP",
"sameAsBilling": 1
},
"shippingCarrierCode": "flatrate",
"shippingMethodCode": "flatrate"
}
}

Add Shipping Information for Guest Cart PayPal Payment Steps

Response:

{
"payment_methods": [
{
"code": "paypal_express",
"title": "PayPal Credit (Paypal Express)"
},
{
"code": "paypal_express",
"title": "PayPal Express Checkout"
}
],
"totals": {
"grand_total": 133,
"base_grand_total": 133,
"subtotal": 133,
"base_subtotal": 133,
"discount_amount": 0,
"base_discount_amount": 0,
"subtotal_with_discount": 133,
"base_subtotal_with_discount": 133,
"shipping_amount": 0,
"base_shipping_amount": 0,
"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": 133,
"shipping_incl_tax": 0,
"base_shipping_incl_tax": 0,
"base_currency_code": "USD",
"quote_currency_code": "USD",
"items_qty": 1,
"items": [
{
"item_id": 1009,
"price": 133,
"base_price": 133,
"qty": 1,
"row_total": 133,
"base_row_total": 133,
"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": 133,
"base_price_incl_tax": 133,
"row_total_incl_tax": 133,
"base_row_total_incl_tax": 133,
"options": "[]",
"weee_tax_applied_amount": null,
"weee_tax_applied": null,
"name": "accessories mono c"
}
],
"total_segments": [
{
"code": "subtotal",
"title": "Subtotal",
"value": 133
},
{
"code": "shipping",
"title": "Shipping & Handling (By DEN - By DEN)",
"value": 0
},
{
"code": "tax",
"title": "Tax",
"value": 0,
"extension_attributes": {
"tax_grandtotal_details": []
}
},
{
"code": "grand_total",
"title": "Grand Total",
"value": 133,
"area": "footer"
}
]
}
}

 

Step 6: Add Payment Information And Place The Order

Now add the payment option in the body and hit the rest api.

You will get a response.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/ewWBDaATec0fKEo15lZkGzEiaoZ1p6sh/order

Method: PUT

Header:

  • Content-Type: application/json
  • Authorization: Bearer Admin_Token

Body: 

{ "paymentMethod": { "method": "paypal_express" } }

Payment Information API Magento 2

Response:

1

 

Step 7: Complete PayPal Payment - Guest Cart Paypal payment Steps

Now follow the below step to complete the transaction.

Now click on the link given below to complete your PayPal payment.

Then in the next step follow the step by step PayPal payment mentioned in the post

How to Make Payment Using PayPal REST API in Magento 2

 

 

Similar Posts:

Get Customer Detail Using Email ID in Magento 2 REST API