degaray / openpay-magento2-module
Magento2的OpenPay模块,墨西哥的支付网关
Requires
- php: ~5.5.0|~5.6.0|~7.0.0|~7.1.0
- degaray/openpay-php-client: dev-master
- magento/magento-composer-installer: *
- magento/module-checkout: *
- magento/module-config: *
- magento/module-customer: *
- magento/module-directory: *
- magento/module-quote: *
- magento/module-sales: *
This package is not auto-updated.
Last update: 2024-09-18 18:58:56 UTC
README
目前,此模块仅考虑作为Magento2模块使用,并使用其REST API。然而,您总是欢迎开发控制器或对其添加额外的功能。
如何使用此模块
配置OpenPay支付密钥。
进入Magento2管理员面板,转到 商店 > 配置 > 销售与结算 > 支付方法 > OpenPay 并 启用 支付方式,然后在正确的字段中输入OpenPay提供的所有信息。如果您想使用沙箱凭据,则从 Modo pruebas (Sandbox) 选择 是;如果您想使用生产凭据,则选择 否。
创建一张卡
要创建一张卡,您首先需要在前端创建一个卡令牌 查看如何创建 以及一个设备会话ID 查看如何创建。
然后您可以在创建新客户 [POST] 时创建卡,或者在更新客户 [PUT] 时创建卡。在任何情况下,您只需要发送一个额外的 Card 对象作为 extension_attribute。使用此模块创建卡的唯一方式是通过令牌。因此,您需要发送一个空的 Card 对象,只填写 token 和 device_session_id。
注意:此模块寻找所有作为
extension_attributes发送的新的令牌,并据此创建卡。
以下是如何创建卡的示例,一个是使用POST调用,另一个是使用PUT调用
[POST] /rest/v1/customers
请求
正文
{
"customer": {
"email": "example@domain.com",
"firstname": "Pedro",
"lastname": "Juárez",
"storeId": 1,
"websiteId": 1,
"addresses": [
{
"country_id": "MX",
"street": [
"Some address 23"
],
"telephone": "5555555558",
"postcode": "09823",
"city": "México",
"firstname": "Pedro",
"lastname": "Juárez",
"default_shipping": true,
"default_billing": true
}
],
"extension_attributes": {
"openpay_card": [
{
"token": null,
"device_session_id": null
]
}
},
"password": "a_Wi3rd_P4zzw0rt"
}
响应
{
"id": 1,
"group_id": 1,
"default_billing": "1",
"default_shipping": "1",
"created_at": "2015-12-15 00:44:20",
"updated_at": "2016-01-04 22:19:24",
"created_in": "Default Store View",
"email": "example@domain.com",
"firstname": "Pedro",
"lastname": "Juárez",
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 1,
"customer_id": 1,
"region": {
"region_code": null,
"region": null,
"region_id": 0
},
"region_id": 0,
"country_id": "MX",
"street": [
"Some address 23"
],
"telephone": "5555555558",
"postcode": "09823",
"city": "México",
"firstname": "Pedro",
"lastname": "Juárez",
"default_shipping": true,
"default_billing": true
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"openpay_card": [
{
"customer_id": "atxdxf8dtsfiqj6jlykp",
"card_id": "krotlgka8xqeebtxpjf9",
"created_at": "2016-01-04T16:18:32-06:00",
"updated_at": null,
"token": null,
"device_session_id": null,
"type": "debit",
"brand": "visa",
"card_number": "411111XXXXXX1111",
"holder_name": "Pedro Juarez Ramirez",
"expiration_year": "20",
"expiration_month": "12",
"allows_charges": false,
"allows_payouts": true,
"bank_name": "Banamex",
"bank_code": "002",
"address": {
"city": "Querétaro",
"country_code": "MX",
"line1": "Av 5 de Febrero",
"line2": "Roble 207",
"line3": "col carrillo",
"postal_code": "76900",
"state": "Queretaro"
}
}
]
},
"custom_attributes": [
{
"attribute_code": "openpay_customer_id",
"value": "atxdxfodtsfiqj4jlykp"
}
]
}
[PUT] /rest/v1/customers/me
请求
正文
{
"customer": {
"id": 1,
"email": "example@domain.com",
"firstname": "Pedro",
"lastname": "Juárez",
"storeId": 1,
"websiteId": 1,
"addresses": [
{
"country_id": "MX",
"street": [
"Some address 23"
],
"telephone": "5555555558",
"postcode": "09823",
"city": "México",
"firstname": "Pedro",
"lastname": "Juárez",
"default_shipping": true,
"default_billing": true
}
],
"extension_attributes": {
"openpay_card": [
{
"token": null,
"device_session_id": null
}
]
}
}
}
响应
{
"id": 1,
"group_id": 1,
"default_billing": "1",
"default_shipping": "1",
"created_at": "2015-12-15 00:44:20",
"updated_at": "2016-01-04 22:19:24",
"created_in": "Default Store View",
"email": "example@domain.com",
"firstname": "Pedro",
"lastname": "Juárez",
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 1,
"customer_id": 1,
"region": {
"region_code": null,
"region": null,
"region_id": 0
},
"region_id": 0,
"country_id": "MX",
"street": [
"Some address 23"
],
"telephone": "5555555558",
"postcode": "09823",
"city": "México",
"firstname": "Pedro",
"lastname": "Juárez",
"default_shipping": true,
"default_billing": true
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"openpay_card": [
{
"customer_id": "atxdxf8dtsfiqj6jlykp",
"card_id": "krotlgka8xqeebtxpjf9",
"created_at": "2016-01-04T16:18:32-06:00",
"updated_at": null,
"token": null,
"device_session_id": null,
"type": "debit",
"brand": "visa",
"card_number": "411111XXXXXX1111",
"holder_name": "Pedro Juarez Ramirez",
"expiration_year": "20",
"expiration_month": "12",
"allows_charges": false,
"allows_payouts": true,
"bank_name": "Banamex",
"bank_code": "002",
"address": {
"city": "Querétaro",
"country_code": "MX",
"line1": "Av 5 de Febrero",
"line2": "Roble 207",
"line3": "col carrillo",
"postal_code": "76900",
"state": "Queretaro"
}
}
]
},
"custom_attributes": [
{
"attribute_code": "openpay_customer_id",
"value": "atxdxfodtsfiqj4jlykp"
}
]
}
删除一张卡
要删除一张卡,您需要在PUT调用中删除该卡,模块将推断您正在尝试删除该卡。
注意:此模块寻找所有作为
customersextension_attributes发送的卡,并将其与之前保存的卡进行比较。如果请求中不存在现有卡,则模块将删除该卡。
以下是如何删除卡的示例
[PUT] /rest/v1/customers/me
请求
正文
{
"customer": {
"id": 1,
"email": "example@domain.com",
"firstname": "Pedro",
"lastname": "Juárez",
"storeId": 1,
"websiteId": 1,
"addresses": [
{
"country_id": "MX",
"street": [
"Some address 23"
],
"telephone": "5555555558",
"postcode": "09823",
"city": "México",
"firstname": "Pedro",
"lastname": "Juárez",
"default_shipping": true,
"default_billing": true
}
],
"extension_attributes": {
"openpay_card": []
},
"custom_attributes": [
{
"attribute_code": "openpay_customer_id",
"value": "atxdxfodtsfiqj4jlykp"
}
]
}
}
响应
{
"id": 1,
"group_id": 1,
"default_billing": "1",
"default_shipping": "1",
"created_at": "2015-12-15 00:44:20",
"updated_at": "2016-01-04 22:19:24",
"created_in": "Default Store View",
"email": "example@domain.com",
"firstname": "Pedro",
"lastname": "Juárez",
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 1,
"customer_id": 1,
"region": {
"region_code": null,
"region": null,
"region_id": 0
},
"region_id": 0,
"country_id": "MX",
"street": [
"Some address 23"
],
"telephone": "5555555558",
"postcode": "09823",
"city": "México",
"firstname": "Pedro",
"lastname": "Juárez",
"default_shipping": true,
"default_billing": true
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"openpay_card": []
},
"custom_attributes": [
{
"attribute_code": "openpay_customer_id",
"value": "atxdxfodtsfiqj4jlykp"
}
]
}
获取客户卡
要获取指定客户的全部卡,您需要对客户进行 [GET] 请求,响应将包括客户的所有卡,都在 extension_attributes 中。
[GET] /rest/v1/customers/me
响应
{
"id": 1,
"group_id": 1,
"default_billing": "1",
"default_shipping": "1",
"created_at": "2015-12-15 00:44:20",
"updated_at": "2016-01-04 22:19:24",
"created_in": "Default Store View",
"email": "example@domain.com",
"firstname": "Pedro",
"lastname": "Juárez",
"store_id": 1,
"website_id": 1,
"addresses": [
{
"id": 1,
"customer_id": 1,
"region": {
"region_code": null,
"region": null,
"region_id": 0
},
"region_id": 0,
"country_id": "MX",
"street": [
"Some address 23"
],
"telephone": "5555555558",
"postcode": "09823",
"city": "México",
"firstname": "Pedro",
"lastname": "Juárez",
"default_shipping": true,
"default_billing": true
}
],
"disable_auto_group_change": 0,
"extension_attributes": {
"openpay_card": [
{
"customer_id": "atxdxf8dtsfiqj6jlykp",
"card_id": "krotlgka8xqeebtxpjf9",
"created_at": "2016-01-04T16:18:32-06:00",
"updated_at": null,
"token": null,
"device_session_id": null,
"type": "debit",
"brand": "visa",
"card_number": "411111XXXXXX1111",
"holder_name": "Pedro Juarez Ramirez",
"expiration_year": "20",
"expiration_month": "12",
"allows_charges": false,
"allows_payouts": true,
"bank_name": "Banamex",
"bank_code": "002",
"address": {
"city": "Querétaro",
"country_code": "MX",
"line1": "Av 5 de Febrero",
"line2": "Roble 207",
"line3": "col carrillo",
"postal_code": "76900",
"state": "Queretaro"
}
}
]
},
"custom_attributes": [
{
"attribute_code": "openpay_customer_id",
"value": "atxdxfodtsfiqj4jlykp"
}
]
}