Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of Change
Description
Klarna Kustom Checkout (KCO) integration (upto authorization)
Klarna provides two payment methods:
Klarna Payments
Klarna Kustom Checkout
Any one of the methods can be used at a time and switching between Klarna Payments and Klarna Checkout is been done
Based on the PML got, there will be a switching between both Klarna Payments and Klarna Checkout. Klarna Checkout will include the complete checkout process along with payment. The authorization returns an HTML snippet where the user is redirected to complete the payment.
Additional Changes
Motivation and Context
How did you test it?
I tested it using postman by hitting the required endpoints. Curl to the postman setup:
curl --location 'http://localhost:8080/payments'
--header 'Content-Type: application/json'
--header 'Accept: application/json'
--header 'api-key: dev_d8w1F6rbnRBu0NKBZOyxrbCUxoDvEJKPpcEZ0N6c4CHSxJLpZhHjP66cy1cE6YEA'
--data-raw '{
"amount": 5000,
"order_tax_amount": 0,
"currency": "USD",
"amount_to_capture": 5000,
"confirm": true,
"payment_experience":"invoke_sdk_client",
"profile_id": null,
"capture_method": "automatic",
"capture_on": "2022-09-10T10:11:12Z",
"authentication_type": "no_three_ds",
"setup_future_usage":"on_session",
"customer": {
"id": "customer123",
"name": "John Doe",
"email": "[email protected]",
"phone": "9999999999",
"phone_country_code": "+1"
},
"customer_id": "customer123",
"phone_country_code": "+1",
"routing": {
"type": "single",
"data": "stripe"
},
"description": "Its my first payment request",
"return_url": "https://google.com",
"payment_method": "pay_later",
"payment_method_type": "klarna_checkout",
"payment_method_data": {
"pay_later": {
"klarna_checkout":{}
},
"billing":null
},
"billing": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US",
"first_name": "joseph",
"last_name": "Doe"
},
"phone": {
"number": "8056594427",
"country_code": "+91"
},
"email": "[email protected]"
},
"shipping": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US",
"first_name": "joseph",
"last_name": "Doe"
},
"phone": {
"number": "8056594427",
"country_code": "+91"
},
"email": "[email protected]"
},
"statement_descriptor_name": "joseph",
"statement_descriptor_suffix": "JS",
"order_details": [
{
"product_name": "Red T-Shirt",
"quantity": 1,
"amount": 5000,
"account_name": "transaction_processing",
"total_tax_amount": 0,
"tax_rate": 0,
"total_amount": 5000
}
],
"metadata": {
"udf1": "value1",
"new_customer": "true",
"login_date": "2019-09-10T10:11:12Z"
},
"browser_info": {
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
"accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8",
"language": "nl-NL",
"color_depth": 24,
"screen_height": 723,
"screen_width": 1536,
"time_zone": 0,
"java_enabled": true,
"java_script_enabled": true,
"ip_address": "128.0.0.1"
},
"customer_acceptance": {
"acceptance_type": "offline",
"accepted_at": "1963-05-03T04:07:52.723Z",
"online": {
"ip_address": "125.0.0.1",
"user_agent": "amet irure esse"
}
},
"connector_metadata": {
"noon": {
"order_category": "pay"
}
},
"payment_link": false,
"payment_link_config": {
"theme": "",
"logo": "",
"seller_name": "",
"sdk_layout": "",
"display_sdk_only": false,
"enabled_saved_payment_method": false
},
"payment_type": "normal",
"request_incremental_authorization": false,
"merchant_order_reference_id": "test_ord",
"merchant_urls": {
"terms": "https://www.example.com/terms.html",
"checkout": "https://www.example.com/checkout.html?order_id={checkout.order.id}",
"confirmation": "https://www.example.com/confirmation.html?order_id={checkout.order.id}",
"push": "https://www.example.com/api/push?order_id={checkout.order.id}"
}
}
'
Request body:
{
"amount": 5000,
"order_tax_amount": 0,
"currency": "USD",
"amount_to_capture": 5000,
"confirm": true,
"payment_experience":"invoke_sdk_client",
"profile_id": {{profile_id}},
"capture_method": "automatic",
"capture_on": "2022-09-10T10:11:12Z",
"authentication_type": "no_three_ds",
"setup_future_usage":"on_session",
"customer": {
"id": "customer123",
"name": "John Doe",
"email": "[email protected]",
"phone": "9999999999",
"phone_country_code": "+1"
},
"customer_id": "customer123",
"phone_country_code": "+1",
"routing": {
"type": "single",
"data": "stripe"
},
"description": "Its my first payment request",
"return_url": "https://google.com",
"payment_method": "pay_later",
"payment_method_type": "klarna_checkout",
"payment_method_data": {
"pay_later": {
"klarna_checkout":{}
},
"billing":null
},
"billing": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US",
"first_name": "joseph",
"last_name": "Doe"
},
"phone": {
"number": "8056594427",
"country_code": "+91"
},
"email": "[email protected]"
},
"shipping": {
"address": {
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"city": "San Fransico",
"state": "California",
"zip": "94122",
"country": "US",
"first_name": "joseph",
"last_name": "Doe"
},
"phone": {
"number": "8056594427",
"country_code": "+91"
},
"email": "[email protected]"
},
"statement_descriptor_name": "joseph",
"statement_descriptor_suffix": "JS",
"order_details": [
{
"product_name": "Red T-Shirt",
"quantity": 1,
"amount": 5000,
"account_name": "transaction_processing",
"total_tax_amount": 0,
"tax_rate": 0,
"total_amount": 5000
}
],
"metadata": {
"udf1": "value1",
"new_customer": "true",
"login_date": "2019-09-10T10:11:12Z"
},
"browser_info": {
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
"accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8",
"language": "nl-NL",
"color_depth": 24,
"screen_height": 723,
"screen_width": 1536,
"time_zone": 0,
"java_enabled": true,
"java_script_enabled": true,
"ip_address": "128.0.0.1"
},
"customer_acceptance": {
"acceptance_type": "offline",
"accepted_at": "1963-05-03T04:07:52.723Z",
"online": {
"ip_address": "125.0.0.1",
"user_agent": "amet irure esse"
}
},
"connector_metadata": {
"noon": {
"order_category": "pay"
}
},
"payment_link": false,
"payment_link_config": {
"theme": "",
"logo": "",
"seller_name": "",
"sdk_layout": "",
"display_sdk_only": false,
"enabled_saved_payment_method": false
},
"payment_type": "normal",
"request_incremental_authorization": false,
"merchant_order_reference_id": "test_ord",
"merchant_urls": {
"terms": "https://www.example.com/terms.html",
"checkout": "https://www.example.com/checkout.html?order_id={checkout.order.id}",
"confirmation": "https://www.example.com/confirmation.html?order_id={checkout.order.id}",
"push": "https://www.example.com/api/push?order_id={checkout.order.id}"
}
}
Response got:
{
"payment_id": "pay_QlHDOrast5uUHJunpu6w",
"merchant_id": "merchant_1731619362",
"status": "requires_customer_action",
"amount": 5000,
"net_amount": 5000,
"shipping_cost": null,
"amount_capturable": 5000,
"amount_received": null,
"connector": "klarna",
"client_secret": "pay_QlHDOrast5uUHJunpu6w_secret_vludcGDtQX7nwTcRvf5b",
"created": "2024-11-18T05:43:10.080Z",
"currency": "USD",
"customer_id": "customer123",
"customer": {
"id": "customer123",
"name": "John Doe",
"email": "[email protected]",
"phone": "9999999999",
"phone_country_code": "+1"
},
"description": "Its my first payment request",
"refunds": null,
"disputes": null,
"mandate_id": null,
"mandate_data": null,
"setup_future_usage": "on_session",
"off_session": null,
"capture_on": null,
"capture_method": "automatic",
"payment_method": "pay_later",
"payment_method_data": {
"pay_later": {
"klarna_sdk": null,
"klarna_checkout": null
},
"billing": null
},
"payment_token": null,
"shipping": {
"address": {
"city": "San Fransico",
"country": "US",
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"zip": "94122",
"state": "California",
"first_name": "joseph",
"last_name": "Doe"
},
"phone": {
"number": "8056594427",
"country_code": "+91"
},
"email": "[email protected]"
},
"billing": {
"address": {
"city": "San Fransico",
"country": "US",
"line1": "1467",
"line2": "Harrison Street",
"line3": "Harrison Street",
"zip": "94122",
"state": "California",
"first_name": "joseph",
"last_name": "Doe"
},
"phone": {
"number": "8056594427",
"country_code": "+91"
},
"email": "[email protected]"
},
"order_details": [
{
"brand": null,
"amount": 5000,
"category": null,
"quantity": 1,
"tax_rate": 0,
"product_id": null,
"product_name": "Red T-Shirt",
"product_type": null,
"sub_category": null,
"product_img_link": null,
"product_tax_code": null,
"total_tax_amount": 0,
"requires_shipping": null
}
],
"email": "[email protected]",
"name": "John Doe",
"phone": "9999999999",
"return_url": "https://google.com/",
"authentication_type": "no_three_ds",
"statement_descriptor_name": "joseph",
"statement_descriptor_suffix": "JS",
"next_action": {
"type": "redirect_to_url",
"redirect_to_url": "http://localhost:8080/payments/redirect/pay_QlHDOrast5uUHJunpu6w/merchant_1731619362/pay_QlHDOrast5uUHJunpu6w_1"
},
"cancellation_reason": null,
"error_code": null,
"error_message": null,
"unified_code": null,
"unified_message": null,
"payment_experience": "invoke_sdk_client",
"payment_method_type": "klarna_checkout",
"connector_label": null,
"business_country": null,
"business_label": "default",
"business_sub_label": null,
"allowed_payment_method_types": null,
"ephemeral_key": {
"customer_id": "customer123",
"created_at": 1731908589,
"expires": 1731912189,
"secret": "epk_71b7ee6469054c4685e22788757d7374"
},
"manual_retry_allowed": null,
"connector_transaction_id": "d76bbafe-ca78-4516-a573-9eaad4f62425",
"frm_message": null,
"metadata": {
"udf1": "value1",
"login_date": "2019-09-10T10:11:12Z",
"new_customer": "true"
},
"connector_metadata": {
"apple_pay": null,
"airwallex": null,
"noon": {
"order_category": "pay"
}
},
"feature_metadata": null,
"reference_id": null,
"payment_link": null,
"profile_id": "pro_6Siq366EXAv0bzraYUyb",
"surcharge_details": null,
"attempt_count": 1,
"merchant_decision": null,
"merchant_connector_id": "mca_E55SteisYLSojm3d7bwZ",
"incremental_authorization_allowed": false,
"authorization_count": null,
"incremental_authorizations": null,
"external_authentication_details": null,
"external_3ds_authentication_attempted": false,
"expires_on": "2024-11-18T05:58:10.080Z",
"fingerprint": null,
"browser_info": {
"language": "nl-NL",
"time_zone": 0,
"ip_address": "128.0.0.1",
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
"color_depth": 24,
"java_enabled": true,
"screen_width": 1536,
"accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8",
"screen_height": 723,
"java_script_enabled": true
},
"payment_method_id": null,
"payment_method_status": null,
"updated": "2024-11-18T05:43:11.416Z",
"charges": null,
"frm_metadata": null,
"merchant_order_reference_id": "test_ord",
"order_tax_amount": null,
"connector_mandate_id": null
}
Checklist
cargo +nightly fmt --all
cargo clippy