-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
13 changed files
with
189 additions
and
9 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
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,60 @@ | ||
package exchequer | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/adyen/adyen-go-api-library/v11/src/checkout" | ||
"github.com/adyen/adyen-go-api-library/v11/src/common" | ||
"github.com/gin-gonic/gin" | ||
"github.com/gin-gonic/gin/binding" | ||
"github.com/rotationalio/exchequer/pkg/api/v1" | ||
"github.com/rotationalio/exchequer/pkg/ulids" | ||
) | ||
|
||
func (s *Server) Checkout(c *gin.Context) { | ||
origin, _ := url.Parse(s.conf.Origin) | ||
|
||
// Create the checkout request object | ||
key := ulids.New() | ||
returnURL := origin.JoinPath("/checkout/complete") | ||
returnURL.RawQuery = url.Values{"session": []string{key.String()}}.Encode() | ||
|
||
sessionRequest := checkout.CreateCheckoutSessionRequest{ | ||
Reference: "INV-0001", | ||
Amount: checkout.Amount{ | ||
Currency: "USD", | ||
Value: 1000, | ||
}, | ||
MerchantAccount: s.conf.Adyen.MerchantAccount, | ||
CountryCode: common.PtrString("US"), | ||
ReturnUrl: returnURL.String(), | ||
} | ||
|
||
// Send the request to Adyen | ||
service := s.adyen.Checkout() | ||
req := service.PaymentsApi.SessionsInput().IdempotencyKey(key.String()).CreateCheckoutSessionRequest(sessionRequest) | ||
rep, _, err := service.PaymentsApi.Sessions(c.Request.Context(), req) | ||
|
||
if err != nil { | ||
c.Error(err) | ||
c.Negotiate(http.StatusOK, gin.Negotiate{ | ||
Offered: []string{binding.MIMEJSON, binding.MIMEHTML}, | ||
Data: api.Error("could not create checkout session with adyen"), | ||
HTMLName: "500.html", | ||
}) | ||
return | ||
} | ||
|
||
out := gin.H{ | ||
"ClientKey": s.conf.Adyen.ClientKey, | ||
"SessionID": rep.Id, | ||
"SessionData": *rep.SessionData, | ||
} | ||
|
||
c.Negotiate(http.StatusOK, gin.Negotiate{ | ||
Offered: []string{binding.MIMEJSON, binding.MIMEHTML}, | ||
Data: out, | ||
HTMLName: "checkout.html", | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
html, body { | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
#adyen-dropin { | ||
max-width: 920px; | ||
} |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
<section class=""> | ||
<h1>Internal Server Error</h1> | ||
<p>{{ .Error }}</p> | ||
</section> | ||
|
||
{{ end }} |
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,58 @@ | ||
{{ template "base" . }} | ||
{{ define "styles" }} | ||
<!-- Embed the Adyen Web stylesheet. You can add your own styling by overriding the rules in the CSS file --> | ||
<link rel="stylesheet" href="https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/5.66.1/adyen.css" | ||
integrity="sha384-gpOE6R0K50VgXe6u/pyjzkKl4Kr8hXu93KUCTmC4LqbO9mpoGUYsrmeVLcp2eejn" | ||
crossorigin="anonymous"> | ||
{{ end }} | ||
|
||
{{ define "content" }} | ||
|
||
<section class="text-center py-14"> | ||
<h1>Checkout</h1> | ||
<div id="adyen-dropin"></div> | ||
</section> | ||
|
||
{{ end }} | ||
|
||
{{ define "appcode" }} | ||
<!-- Embed the Adyen Web script element above any other JavaScript in your checkout page. --> | ||
<script src="https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/5.66.1/adyen.js" | ||
integrity="sha384-1hIjspaI91zaZaaFP4++yNNBE9emITOdAAnKcDsVFvA8agUeXq/b9Fh+9q0fx2/2" | ||
crossorigin="anonymous"></script> | ||
<script> | ||
const configuration = { | ||
environment: "test", | ||
clientKey: "{{ .ClientKey }}", | ||
analytics: { | ||
enabled: true | ||
}, | ||
session: { | ||
id: "{{ .SessionID }}", | ||
sessionData: "{{ .SessionData }}" | ||
}, | ||
onPaymentCompleted: (result, component) => { | ||
console.info(result, component); | ||
}, | ||
onError: (error, component) => { | ||
console.error(error.name, error.message, error.stack, component); | ||
}, | ||
paymentMethodsConfiguration: { | ||
card: { | ||
hasHolderName: true, | ||
holderNameRequired: true, | ||
billingAddressRequired: true | ||
} | ||
} | ||
}; | ||
|
||
const setupAdyen = async () => { | ||
console.log("setting up adyen dropin"); | ||
const checkout = await AdyenCheckout(configuration); | ||
const dropinComponent = checkout.create('dropin').mount('#adyen-dropin'); | ||
console.log("adyen dropin configuration complete"); | ||
} | ||
|
||
setupAdyen(); | ||
</script> | ||
{{ end }} |
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