solidusio / solidus_bolt

BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link

Void Payment by Webhook #34

Closed DanielePalombo closed 2 years ago

DanielePalombo commented 2 years ago

When Transation gets in Cancelled state, we have to void the Solidus Payment.

This is the Event payload we'll receive from Bolt:

{
    "type": "void",
    "object": "transaction",
    "data": {
        "id": "TA5dS8mv4KBHp",
        "type": "cc_payment",
        "processor": "vantiv",
        "date": 1650650380858,
        "reference": "XMM7-KLJZ-K9B3",
        "status": "cancelled",
        "from_user": {
            "id": "CA7w2RKPi9PKG",
            "first_name": "Daniele",
            "last_name": "Palombo",
            "phones": [
                {
                    "number": "+1 333222334232",
                    "country_code": "1"
                }
            ],
            "emails": [
                {
                    "address": "danielepalombo@nebulab.com"
                }
            ]
        },
        "from_credit_card": {
            "id": "CAan4YBg23RYj",
            "last4": "1111",
            "bin": "411111",
            "expiration": 1667260800000,
            "network": "Visa",
            "display_network": "Visa",
            "token_type": "bolt",
            "status": "active"
        },
        "amount": {
            "amount": 2000,
            "currency": "USD",
            "currency_symbol": "$"
        },
        "authorization": {
            "auth": "83988858395380762",
            "reason": "none",
            "status": "succeeded"
        },
        "captures": null,
        "refund_transactions": [],
        "risk_signals": {
            "ip_address": "79.35.218.113",
            "time_on_site": "00:00:00",
            "http_headers": {
                "accept": "application/json",
                "accept_encoding": "gzip, deflate, br",
                "accept_language": "en-GB,en-US;q=0.9,en;q=0.8",
                "connection": "",
                "host": "api-sandbox.bolt.com",
                "referer": "https://merchant-sandbox.bolt.com/",
                "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
            }
        },
        "capture_type": "manual"
    }
}

use data.reference to retrieve the payment and advance it to the void state