Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

initial webhooks #205

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,40 @@ Payment abstraction library - interact with different Payment Service Providers

Wherever possible, we try to use native Golang implementations of the PsP's API. We also assume that the caller can pass along raw credit card information (i.e. are PCI compliant)

### Supported API Calls
### Supported Gateway API Calls

1. Authorize
2. Capture
3. Void
4. Refund

### To run tests
### Webhooks Support

#### Unit test
We support abstracting PsP Webhook notifications into a common event interface.

### PsP Support Matrix
| PsP | Gateway APIs | Webhooks (Beta) |
|-----|--------------|----------|
| [Adyen](https://docs.adyen.com/classic-integration/api-integration-ecommerce) | ✅ | ✅ |
| [Authorize.Net](https://developer.authorize.net/api/reference/index.html#payment-transactions) | ✅ | ❌ |
| [Braintree](https://www.braintreepayments.com/) | ✅ | ❌ |
| [CyberSource](https://developer.cybersource.com/api-reference-assets/index.html#payments) | ✅ | ❌ |
| [Checkout.com](https://api-reference.checkout.com/) | ✅ | ❌ |
| [FirstData](https://docs.firstdata.com/org/gateway/docs/api) | ✅ | ❌ |
| [NMI](https://secure.networkmerchants.com/gw/merchants/resources/integration/integration_portal.php#methodology) | ✅ | ❌ |
| [Orbital](https://developer.jpmorgan.com/products/orbital-api) | ✅ | ❌ |
| [RocketGate](https://www.rocketgate.com/) | ✅ | ❌ |
| [Stripe](https://stripe.com/docs/api) | ✅ | ✅ |

## To run tests

### Unit test

```
go test -v -tags=unit $(go list ./... | grep -v integration-tests)
```

#### Integration test
### Integration test
The following environment variables are needed in order to run tests

```shell script
Expand All @@ -51,7 +69,7 @@ $ export CHECKOUTCOM_TEST_KEY="YOUR_CHECKOUTCOM_PRIVATE_KEY"

Then run tests with: `go test ./integration-tests/`

#### Code Example for Auth + Capture
## Code Example for Auth + Capture

```
import (
Expand Down Expand Up @@ -97,13 +115,4 @@ captureRequest := sleet.CaptureRequest{
TransactionReference: authorizeResponse.TransactionReference,
}
client.Capture(&captureRequest)
```

#### Supported Gateways

- [Authorize.Net](https://developer.authorize.net/api/reference/index.html#payment-transactions)
- [CyberSource](https://developer.cybersource.com/api-reference-assets/index.html#payments)
- [Stripe](https://stripe.com/docs/api)
- [Adyen](https://docs.adyen.com/classic-integration/api-integration-ecommerce)
- [Braintree](https://www.braintreepayments.com/)
- [NMI](https://secure.networkmerchants.com/gw/merchants/resources/integration/integration_portal.php#methodology)
```
29 changes: 29 additions & 0 deletions webhooks/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package webhooks

import "github.com/BoltApp/sleet"

// WebhookTranslator Sleet interface which takes an eventBody and translates the body to the
// Sleet TransactionEvent. Normalizes all fields to the structure and enums defined by Sleet.
type WebhookTranslator interface {
Translate(eventBody *string) (*TransactionEvent, error)
}

type TransactionEventType int

const (
CaptureEvent TransactionEventType = 1
VoidEvent TransactionEventType = 2
RefundEvent TransactionEventType = 3
)

type TransactionEvent struct {
// Core event fields, these should be included in every transaction event
transactionEventType TransactionEventType // Normalized event type for the transaction
transactionReferenceId *string // id representing the transaction on the PsP system
success bool // normalized indicator on event representing success or not

// Optional event fields, may be available based on the event type or processor implementation
merchantTransactionReferenceId *string // id representing the transaction on caller's system (as passed to the PsP if supported)
amount sleet.Amount

}