Skip to main content

Documentation

Create a Payment in Python

After you have made your first API call, you can create a payment directly via the Rapyd API in any programming language.

Before You Send Your Request

Make sure you have completed Make Your First API Call to set your authentication headers and request signature to get a successful response.

Create a Payment

The Rapyd API allows you to accept payments from your customers directly into your platform.

Note: Clients with PCI-DSS certification can handle personal identifying information for credit and debit cards.

  1. Copy the Python code sample below, or use other code samples under Create Payment Request on the Card Payments page.

      • Request

        •               
          from pprint import pprint
          
          from utilities import make_request
          
          data = {
              "amount": "50.00",
              "currency": "EUR",
              "payment_method": {
                  "type": "gb_visa_card",
                  "fields": {
                      "number": "4111111111111111",
                      "expiration_month": "12",
                      "expiration_year": "27",
                      "cvv": "567",
                      "name": "John Doe"
                  }
              }
          }
          response = make_request(method='post',
                                  path='/v1/payments',
                                  body=data)
          pprint(response)
          

    Note: For a description of all the parameters, see Payment Object.

  2. Save the file next to your utilities file (e.g. create-payment.py).

  3. Execute your file (e.g. python3 create-payment.py) and receive your response.

    • Response

      •               
         {
            "status": {
                "error_code": "",
                "status": "SUCCESS",
                "message": "",
                "response_code": "",
                "operation_id": "03dd96b5-1546-47c5-9ea8-26ea7f9392e6"
            },
            "data": {
                "id": "payment_9899b33317123dc59427fb0a4aa3f4f7",
                "amount": 50,
                "original_amount": 50,
                "is_partial": false,
                "currency_code": "GBP",
                "country_code": "GB",
                "status": "CLO",
                "description": "",
                "merchant_reference_id": "",
                "customer_token": "cus_183225bd57e4bc4967bf8b4ddc9c6144",
                "payment_method": "card_5a451b226ebcee4511fb22b199532ba2",
                "payment_method_data": {
                    "id": "card_5a451b226ebcee4511fb22b199532ba2",
                    "type": "gb_visa_card",
                    "category": "card",
                    "metadata": {
                        "merchant_defined": true
                    },
                    "image": "",
                    "webhook_url": "",
                    "supporting_documentation": "",
                    "next_action": "not_applicable",
                    "name": "John Doe",
                    "last4": "1111",
                    "acs_check": "unchecked",
                    "cvv_check": "unchecked",
                    "bin_details": {
                        "type": null,
                        "brand": null,
                        "level": null,
                        "issuer": null,
                        "country": null,
                        "bin_number": "411111"
                    },
                    "expiration_year": "27",
                    "expiration_month": "12",
                    "fingerprint_token": "ocfp_2a694038316f52122bbbb3ae926cfda9"
                },
                "auth_code": null,
                "expiration": 1692142435,
                "captured": true,
                "refunded": false,
                "refunded_amount": 0,
                "receipt_email": "",
                "redirect_url": "",
                "complete_payment_url": "",
                "error_payment_url": "",
                "receipt_number": "",
                "flow_type": "",
                "address": null,
                "statement_descriptor": "Test Business",
                "transaction_id": "",
                "created_at": 1691537634,
                "metadata": {},
                "failure_code": "",
                "failure_message": "",
                "paid": true,
                "paid_at": 1691537635,
                "dispute": null,
                "refunds": null,
                "order": null,
                "outcome": null,
                "visual_codes": {},
                "textual_codes": {},
                "instructions": [],
                "ewallet_id": "ewallet_db4ad4a76278f94c4a83dd9b28b483ed",
                "ewallets": [
                    {
                        "ewallet_id": "ewallet_db4ad4a76278f94c4a83dd9b28b483ed",
                        "amount": 50,
                        "percent": 100,
                        "refunded_amount": 0
                    }
                ],
                "payment_method_options": {},
                "payment_method_type": "gb_visa_card",
                "payment_method_type_category": "card",
                "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": "not_applicable",
                "error_code": "",
                "remitter_information": {},
                "save_payment_method": true
            }
        }       

Rapyd Samples

See the Rapyd Github Repository for more examples.