📜  elavon 收敛 api python 教程 - Python (1)

📅  最后修改于: 2023-12-03 15:30:36.495000             🧑  作者: Mango

Elavon 收敛 API Python 教程 - Python

Elavon 收敛 API Python 教程将向您介绍 Elavon 收敛 API 和如何在 Python 中使用它。

什么是 Elavon 收敛 API?

Elavon 是一家总部位于爱尔兰的金融服务公司,提供各种支付处理和支付解决方案。Elavon 提供收敛 API,使商家可以在自己的网站上接收和处理信用卡和借记卡付款。

收敛 API 允许您将付款处理与您网站上的其余部分无缝集成。这使您的客户能够在不离开您的网站的情况下进行付款,从而提高您的销售量和客户体验。

如何使用 Elavon 收敛 API?

要使用 Elavon 收敛 API,您需要注册 Elavon 商家帐户。然后,您可以使用 Elavon 提供的 API 文档了解如何在您的网站上集成付款处理。

1. 安装依赖

在 Python 中使用 Elavon 收敛 API,您需要使用 requests 和 json 包。您可以使用 pip 安装这些包。

pip install requests
pip install json
2. 连接到 Elavon 收敛 API

要连接到 Elavon 收敛 API,您需要使用以下代码段。

import requests
import json

# Set up the API endpoint and headers
url = "https://api.elavon.com/virtualMerchant/order.do"
headers = {"Content-type": "application/json"}

# Set up the order dictionary
order_dict = {
  "ssl_merchant_id": "your_merchant_id_here",
  "ssl_user_id": "your_user_id_here",
  "ssl_pin": "your_pin_here",
  "ssl_transaction_type": "ccsale",
  "ssl_amount": 10.00,
  "ssl_card_number": "4111111111111111",
  "ssl_exp_date": "1220",
  "ssl_cvv2cvc2_indicator": 1,
  "ssl_cvv2cvc2": "123",
  "ssl_avs_address": "123 Main St.",
  "ssl_avs_zip": "12345"
}

# Send the order request to the API
response = requests.post(url, headers=headers, json=order_dict)

# Print the response
print(response.json())
3. 处理 API 响应

Elavon 收敛 API 的响应是一个 JSON 字符串。您可以使用 json 包将响应解析为 Python 字典。

# Parse the response into a Python dictionary
response_dict = json.loads(response.text)

# Print the response dictionary
print(response_dict)
4. 错误处理

Elavon 收敛 API 响应包含一个 result 字段。如果结果为 0,则表示 API 请求已成功处理。如果结果不为 0,则表示出现错误。

# Check for errors in the response dictionary
if response_dict["result"] != 0:
  print("Error processing order:")
  print(response_dict["message"])
结论

Elavon 收敛 API Python 教程介绍了如何在 Python 中使用 Elavon 收敛 API 进行付款处理。连接到 API、处理响应和错误处理,这些步骤将为您提供有关如何使用 Elavon 收敛 API 的基础知识。