Skip to main content

Documentation

Creating a Payment Using Customer Profile Information

Save information to the customer profile, add the payment method to the customer profile and create the payment.

This procedure describes how to create a payment using a payment method that requires information that is stored in the customer profile. The payment must include the ID of the Customer object that represents the customer profile. The procedure is made up of the following steps:

  1. Determine the requirements of the payment method.

  2. Create or update a Customer object with the required information. For this example, we will illustrate updating an existing Customer object.

  3. Add the payment method to the customer profile.

  4. Create the payment using the ID of the payment method and the ID of the customer.

Note

Payment methods that require previously stored information cannot be used for guest customers.

1. Get Payment Method Required Fields

To determine whether a payment method requires previously stored information, run Get Payment Method Required Fields. For this example, we will use the gb_trustly_bank payment method.

    • Get Payment Method Required Fields - Request

      • // Request URL: get https://sandboxapi.rapyd.net/v1/payment_methods/required_fields/gb_trustly_bank
        
        // Message body absent
        
    • Get Payment Method Required Fields - Response

      • {
            "status": {
                "error_code": "",
                "status": "SUCCESS",
                "message": "",
                "response_code": "",
                "operation_id": "5f25e66f-e7e7-49c5-bb9e-a7c68734adfc"
            },
            "data": {
                "type": "gb_trustly_bank",
                "fields": [],
                "payment_method_options": [],
                "payment_options": [
                    {
                        "name": "customer",
                        "type": "customer",
                        "regex": "",
                        "description": "ID of a customer object, a string starting with ‘cus_‘. The customer object must contain the fields listed as required, and can contain additional fields listed here.If the customer object does not exist yet, use ‘Create Customer‘",
                        "is_required": true,
                        "is_updatable": false,
                        "required_fields": [
                            {
                                "name": "name",
                                "type": "string",
                                "regex": "^[0-9a-zA-Z ]{1,128}$",
                                "description": "Customer’s full name",
                                "is_required": true,
                                "is_updatable": false
                            },
                            {
                                "name": "email",
                                "type": "string",
                                "regex": "^(?=.{1,100}$)([0-9a-zA-Z_]+@[a-zA-Z_]+?[.]{1}[a-zA-Z]{2,3})$",
                                "description": "Customer’s Email",
                                "is_required": true,
                                "is_updatable": false
                            }
                        ]
                    }
                ],
                "minimum_expiration_seconds": 0,
                "maximum_expiration_seconds": 1209600
            }
        }

The response indicates that the payment requires the ID of a Customer object and the Customer object requires a name field and an email field.

2. Update Customer

To add the email field to the customer, use Update Customer. Note that the name field was required when the customer was created.

    • Update Customer - Request

      • // Request URL: post https://sandboxapi.rapyd.net/v1/customers/cus_45fff0f3d2cfedad62e511b8e8ad138b
        
        // Message body:
        {
            "name": "John Doe",
            "email": "jdoe@rapyd.net"
        }
        
    • Update Customer - Response

      • {
            "status": {
                "error_code": "",
                "status": "SUCCESS",
                "message": "",
                "response_code": "",
                "operation_id": "a0870559-ed00-4e16-b4e0-c8fa06e1790e"
            },
            "data": {
                "id": "cus_45fff0f3d2cfedad62e511b8e8ad138b",
                "delinquent": false,
                "discount": null,
                "name": "John Doe",
                "default_payment_method": "",
                "description": "",
                "email": "jdoe@rapyd.net",
                "phone_number": "",
                "invoice_prefix": "JD-",
                "addresses": [],
                "payment_methods": null,
                "subscriptions": null,
                "created_at": 1655292669,
                "metadata": {
                    "merchant_defined": true
                },
                "business_vat_id": "12345679",
                "ewallet": "ewallet_995bf51af3fb69f02d8d913342df3ab9"
            }
        }

The Customer object now contains the information required by the gb_trustly_bank payment method.

3. Add Payment Method to Customer

To add the gb_trustly_bank payment method to the customer, use Add Payment Method to Customer.

    • Add Payment Method to Customer - Request

      • // Request URL: post https://sandboxapi.rapyd.net/v1/customers/cus_45fff0f3d2cfedad62e511b8e8ad138b/payment_methods
        
        // Message body:
        {
            "type": "gb_trustly_bank",
            "fields": {},
            "metadata": {
                "merchant_defined": true
            }
        }
        
    • Add Payment Method to Customer - Response

      • {
            "status": {
                "error_code": "",
                "status": "SUCCESS",
                "message": "",
                "response_code": "",
                "operation_id": "9b156c6b-9def-4bdd-917a-29c24ae0995a"
            },
            "data": {
                "id": "other_efa080d775f5a252a1ead70ebc99ccc1",
                "type": "gb_trustly_bank",
                "category": "bank_redirect",
                "metadata": {
                    "merchant_defined": true
                },
                "image": "",
                "webhook_url": "",
                "supporting_documentation": "",
                "next_action": "not_applicable",
                "bic_swift": "",
                "account_last4": ""
            }
        }

The Customer object now holds the gb_trustly_bank payment method. Its ID appears in the id field.

4. Create Payment with Updated Customer

To create a payment, use Create Payment. Note that the ID of the payment method is required by the 'Create Payment' method, and the ID of the customer is required by the payment method.

    • Create Payment with Updated Customer - Request

      • // Request URL: post https://sandboxapi.rapyd.net/v1/payments
        
        
        // Message body:
        {
                "amount": 100,
                "currency": "eur",
                "description": "Payment by bank redirect",
          "customer":"cus_45fff0f3d2cfedad62e511b8e8ad138b",
                "payment_method": "other_efa080d775f5a252a1ead70ebc99ccc1",
                "ewallets": [
                        {
                                "ewallet": "ewallet_c67c44ec60d5c2e62480aa7c76b3f8b4",
                                "percentage": 100
                        }
                ],
                "metadata": {
                        "merchant_defined": true
                }
        }
    • Create Payment with Updated Customer - Response

      • {
            "status": {
                "error_code": "",
                "status": "SUCCESS",
                "message": "",
                "response_code": "",
                "operation_id": "a7908de1-5c8b-48a2-80de-e157b72b81c6"
            },
            "data": {
                "id": "payment_f8344aaab822a1f513be2ea3ae185b90",
                "amount": 0,
                "original_amount": 100,
                "is_partial": false,
                "currency_code": "EUR",
                "country_code": "gb",
                "status": "ACT",
                "description": "Payment by bank redirect",
                "merchant_reference_id": "",
                "customer_token": "cus_45fff0f3d2cfedad62e511b8e8ad138b",
                "payment_method": "other_efa080d775f5a252a1ead70ebc99ccc1",
                "payment_method_data": {
                    "id": "other_efa080d775f5a252a1ead70ebc99ccc1",
                    "type": "gb_trustly_bank",
                    "category": "bank_redirect",
                    "metadata": {
                        "merchant_defined": true
                    },
                    "image": "",
                    "webhook_url": "",
                    "supporting_documentation": "",
                    "next_action": "not_applicable",
                    "bic_swift": "",
                    "account_last4": ""
                },
                "expiration": 1656503090,
                "captured": true,
                "refunded": false,
                "refunded_amount": 0,
                "receipt_email": "",
                "redirect_url": "https://sandboxcheckout.rapyd.net/complete-bank-payment?token=payment_f8344aaab822a1f513be2ea3ae185b90&complete_payment_url=&error_payment_url=",
                "complete_payment_url": "",
                "error_payment_url": "",
                "receipt_number": "",
                "flow_type": "",
                "address": null,
                "statement_descriptor": "Doc Team",
                "transaction_id": "",
                "created_at": 1655293490,
                "metadata": {
                    "merchant_defined": true
                },
                "failure_code": "",
                "failure_message": "",
                "paid": false,
                "paid_at": 0,
                "dispute": null,
                "refunds": null,
                "order": null,
                "outcome": null,
                "visual_codes": {},
                "textual_codes": {},
                "instructions": [
                    {
                        "name": "instructions",
                        "steps": [
                            {
                                "step1": "Log in to your online banking website to complete an online bank transfer"
                            }
                        ]
                    }
                ],
                "ewallet_id": "ewallet_c67c44ec60d5c2e62480aa7c76b3f8b4",
                "ewallets": [
                    {
                        "ewallet_id": "ewallet_c67c44ec60d5c2e62480aa7c76b3f8b4",
                        "amount": 100,
                        "percent": 100,
                        "refunded_amount": 0
                    }
                ],
                "payment_method_options": {},
                "payment_method_type": "gb_trustly_bank",
                "payment_method_type_category": "bank_redirect",
                "fx_rate": 1,
                "merchant_requested_currency": null,
                "merchant_requested_amount": null,
                "fixed_side": "",
                "payment_fees": null,
                "invoice": "",
                "escrow": null,
                "group_payment": "",
                "cancel_reason": null,
                "initiation_type": "customer_present",
                "mid": "",
                "next_action": "pending_confirmation",
                "error_code": "",
                "remitter_information": {}
            }
        }

Note that this particular payment method requires confirmation from the customer.