-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ff1e95
commit d425498
Showing
7 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package flutterwave | ||
|
||
// GetPaymentLinkRequest is data needed to create a payment link | ||
type GetPaymentLinkRequest struct { | ||
TransactionReference string `json:"tx_ref"` | ||
Amount string `json:"amount"` | ||
Currency string `json:"currency"` | ||
Meta map[string]interface{} `json:"meta"` | ||
RedirectURL string `json:"redirect_url"` | ||
Customer GetPaymentLinkCustomer `json:"customer"` | ||
Customizations GetPaymentLinkCustomizations `json:"customizations"` | ||
} | ||
|
||
// GetPaymentLinkCustomer contains the customer details. | ||
type GetPaymentLinkCustomer struct { | ||
Email string `json:"email"` | ||
Name string `json:"name"` | ||
PhoneNumber string `json:"phonenumber"` | ||
} | ||
|
||
// GetPaymentLinkCustomizations contains options to customize the look of the payment modal. | ||
type GetPaymentLinkCustomizations struct { | ||
Title string `json:"title"` | ||
Logo string `json:"logo"` | ||
} | ||
|
||
// GetPaymentLinkResponse is the data returned after creating a payment link | ||
type GetPaymentLinkResponse struct { | ||
Status string `json:"status"` | ||
Message string `json:"message"` | ||
Data struct { | ||
Link string `json:"link"` | ||
} `json:"data"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package flutterwave | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
// paymentsService is the API client for the `/gateway` endpoint | ||
type paymentsService service | ||
|
||
// GetPaymentLink Call flutterwave to get a payment link, redirect your customer to the link, and flutterwave will redirect back when payment is done. | ||
// | ||
// API Docs: https://developer.flutterwave.com/docs/collecting-payments/standard | ||
func (service *paymentsService) GetPaymentLink(ctx context.Context, payload *GetPaymentLinkRequest) (*GetPaymentLinkResponse, *Response, error) { | ||
request, err := service.client.newRequest(ctx, http.MethodPost, "/v3/payments", payload) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
response, err := service.client.do(request) | ||
if err != nil { | ||
return nil, response, err | ||
} | ||
|
||
var data GetPaymentLinkResponse | ||
if err = json.Unmarshal(*response.Body, &data); err != nil { | ||
return nil, response, err | ||
} | ||
|
||
return &data, response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package flutterwave | ||
|
||
import "time" | ||
|
||
const ( | ||
// HeaderNameVerifHash is the name of the header used to verify your webhook requests. | ||
HeaderNameVerifHash = "verif-hash" | ||
) | ||
|
||
const ( | ||
eventChargeCompleted = "charge.completed" | ||
) | ||
|
||
const ( | ||
statusSuccessful = "successful" | ||
statusFailed = "failed" | ||
) | ||
|
||
// PaymentEventV3 is the payload for webhook requests after a payment | ||
type PaymentEventV3 struct { | ||
Event string `json:"event"` | ||
Data struct { | ||
ID int64 `json:"id"` | ||
TxRef string `json:"tx_ref"` | ||
FlwRef string `json:"flw_ref"` | ||
DeviceFingerprint string `json:"device_fingerprint"` | ||
Amount int `json:"amount"` | ||
Currency string `json:"currency"` | ||
ChargedAmount int `json:"charged_amount"` | ||
AppFee float64 `json:"app_fee"` | ||
MerchantFee int `json:"merchant_fee"` | ||
ProcessorResponse string `json:"processor_response"` | ||
AuthModel string `json:"auth_model"` | ||
IP string `json:"ip"` | ||
Narration string `json:"narration"` | ||
Status string `json:"status"` | ||
PaymentType string `json:"payment_type"` | ||
CreatedAt time.Time `json:"created_at"` | ||
AccountID int `json:"account_id"` | ||
Customer struct { | ||
ID int `json:"id"` | ||
Name string `json:"name"` | ||
PhoneNumber interface{} `json:"phone_number"` | ||
Email string `json:"email"` | ||
CreatedAt time.Time `json:"created_at"` | ||
} `json:"customer"` | ||
Card struct { | ||
First6Digits string `json:"first_6digits"` | ||
Last4Digits string `json:"last_4digits"` | ||
Issuer string `json:"issuer"` | ||
Country string `json:"country"` | ||
Type string `json:"type"` | ||
Expiry string `json:"expiry"` | ||
} `json:"card"` | ||
} `json:"data"` | ||
EventType string `json:"event.type"` | ||
} | ||
|
||
// IsSuccessful checks if the payment event is successfull | ||
func (event PaymentEventV3) IsSuccessful() bool { | ||
return event.Event == eventChargeCompleted && event.Data.Status == statusSuccessful | ||
} | ||
|
||
// IsFailed checks if the payment failed | ||
func (event PaymentEventV3) IsFailed() bool { | ||
return event.Event == eventChargeCompleted && event.Data.Status == statusFailed | ||
} |