Skip to content

Commit 38ddb4f

Browse files
Merge pull request #1 from oscamsmile/main
Update Logo and README file
2 parents 6c92aee + fa7c245 commit 38ddb4f

24 files changed

+4075
-4536
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# connect-payment-integration-monext
1+
# [![Monext Logo](doc/logo-monext.svg)](https://www.monext.fr/)
2+
3+
# Monext Commercetools Connector
24

35
---
46

57
## Table of Content
6-
----
78

89
- [Overview](#overview)
910
- [Template Features](#template-features)
@@ -44,7 +45,7 @@ Their values are taken as input as environment variables/configuration for conne
4445

4546
An API key provided by Monext is necessary to be configured so that the requests from the connect application can be authenticated by Monext platform within the integration. It's value is taken as input as environment variables/configuration for connect with variable name `MONEXT_API_KEY`.
4647

47-
Additionally, some other configuration options provided by Monext and defined by the marchant are required. Their values are taken as input as environment variables/configuration for connect with variable names `MONEXT_ENVIRONMENT`, `MONEXT_POINT_OF_SALE_REF`, `MONEXT_CAPTURE_TYPE`.
48+
Additionally, some other configuration options provided by Monext and defined by the merchant are required. Their values are taken as input as environment variables/configuration for connect with variable names `MONEXT_ENVIRONMENT`, `MONEXT_POINT_OF_SALE_REF`, `MONEXT_CAPTURE_TYPE`.
4849

4950
## Getting started
5051

@@ -148,6 +149,7 @@ Here you can see the details about the variables in configuration:
148149
```
149150
// string - single REF for all stores or for all commercetools project.
150151
MONEXT_POINT_OF_SALE_REF: ref1;
152+
151153
// string JSON valid - if multiple refs for multiple stores
152154
#MONEXT_POINT_OF_SALE_REF: {
153155
"storeKey1": "ref1",
@@ -160,6 +162,7 @@ MONEXT_POINT_OF_SALE_REF: ref1;
160162
```
161163
// string - single capture type for all stores or for all commercetools project
162164
MONEXT_CAPTURE_TYPE: "AUTOMATIC";
165+
163166
// string JSON valid - if multiple Capture types for multiple stores
164167
#MONEXT_CAPTURE_TYPE: {
165168
"storeKey1": "AUTOMATIC",
@@ -172,6 +175,7 @@ MONEXT_CAPTURE_TYPE: "AUTOMATIC";
172175
```
173176
// string - single environment for all stores or for all commercetools project
174177
MONEXT_ENVIRONMENT: "HOMOLOGATION";
178+
175179
// string JSON valid - if multiple environments for multiple stores
176180
#MONEXT_ENVIRONMENT: {
177181
"storeKey1": "HOMOLOGATION",

enabler/dev-utils/session.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const getSessionId = async (cartId) => {
4343

4444
const sessionMetadata = {
4545
processorUrl: __VITE_PROCESSOR_URL__,
46-
allowedPaymentMethods: ["monext"], // add here your allowed methods for development purposes
46+
merchantReturnUrl: __VITE_RETURN_URL__,
4747
};
4848

4949
const url = `${__VITE_CTP_SESSION_URL__}/${projectKey}/sessions`;

enabler/index.html

Lines changed: 104 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,25 @@
6161
<h1 class="h3 mb-3 font-weight-normal">Dev Site</h1>
6262
<p>Use this site for development purposes</p>
6363
</div>
64-
<div class="form-group">
65-
<label for="cartId">Cart ID:</label>
66-
<input
67-
type="text"
68-
class="form-control"
69-
id="cartId"
70-
/>
64+
<div class="row">
65+
<div class="form-group col-md-6">
66+
<div>
67+
<label for="cartId">Cart ID:</label>
68+
<input
69+
type="text"
70+
class="form-control"
71+
id="cartId"
72+
/>
73+
</div>
74+
</div>
75+
<div class="form-group col-md-6">
76+
<label for="paymentMethod">Payment Method:</label>
77+
<select
78+
class="form-control"
79+
id="paymentMethod"
80+
required
81+
></select>
82+
</div>
7183
</div>
7284
<button
7385
id="createCheckout"
@@ -85,12 +97,61 @@ <h1 class="h3 mb-3 font-weight-normal">Dev Site</h1>
8597
<script type="module">
8698
import { Enabler } from "/src/main.ts";
8799

100+
document.addEventListener("DOMContentLoaded", async () => {
101+
const paymentMethodSelect =
102+
document.getElementById("paymentMethod");
103+
const response = await fetch("http://localhost:9000/jwt/token", {
104+
method: "POST",
105+
headers: {
106+
"Content-Type": "application/json",
107+
},
108+
body: JSON.stringify({
109+
iss: "https://mc-api.europe-west1.gcp.commercetools.com",
110+
sub: "subject",
111+
"https://mc-api.europe-west1.gcp.commercetools.com/claims/project_key": `${__VITE_CTP_PROJECT_KEY__}`,
112+
}),
113+
});
114+
115+
const accessToken = await response.json();
116+
117+
const res = await fetch(
118+
`${__VITE_PROCESSOR_URL__}/operations/payment-components`,
119+
{
120+
method: "GET",
121+
headers: {
122+
Authorization: `Bearer ${accessToken.token}`,
123+
},
124+
}
125+
);
126+
const paymentMethods = await res.json();
127+
paymentMethods.components.forEach((method) => {
128+
const option = document.createElement("option");
129+
option.value = method.type;
130+
option.textContent = method.type;
131+
paymentMethodSelect.appendChild(option);
132+
});
133+
paymentMethods.dropins.forEach((method) => {
134+
const option = document.createElement("option");
135+
option.value = `${method.type}`;
136+
option.textContent = `dropin-${method.type}`;
137+
paymentMethodSelect.appendChild(option);
138+
});
139+
});
140+
88141
document
89142
.getElementById("createCheckout")
90143
.addEventListener("click", async (event) => {
91144
event.preventDefault();
92145
const cartId = document.getElementById("cartId").value;
93-
const sessionId = await getSessionId(cartId);
146+
147+
const paymentMethodSelect =
148+
document.getElementById("paymentMethod");
149+
const selectedValue = paymentMethodSelect.value;
150+
const selectedText =
151+
paymentMethodSelect.options[paymentMethodSelect.selectedIndex]
152+
.text;
153+
const isDropin = selectedText.startsWith("dropin");
154+
const sessionId = await getSessionId(cartId, isDropin);
94155

95156
const enabler = new Enabler({
96157
processorUrl: __VITE_PROCESSOR_URL__,
@@ -106,14 +167,44 @@ <h1 class="h3 mb-3 font-weight-normal">Dev Site</h1>
106167
},
107168
});
108169

109-
enabler.createComponentBuilder("monext").then((builder) => {
110-
const paymentElement = builder.build({
111-
showPayButton: true,
170+
let builder;
171+
172+
if (isDropin) {
173+
builder = await enabler.createDropinBuilder(selectedValue);
174+
const component = await builder.build({
175+
showPayButton: !builder.dropinHasSubmit,
176+
onDropinReady: async () => {
177+
console.log("Dropin Ready");
178+
},
179+
onPayButtonClick: async () => {
180+
// to be used for validation
181+
const termsChecked =
182+
document.getElementById("termsCheckbox").checked;
183+
if (!termsChecked) {
184+
event.preventDefault();
185+
alert("You must agree to the terms and conditions.");
186+
return Promise.reject("error-occurred");
187+
}
188+
return Promise.resolve(); // change to true, to test payment flow
189+
},
112190
});
113-
paymentElement.mount("#monext-component");
114-
});
191+
component.mount("#monext-component");
192+
}
115193
});
116194
</script>
195+
<div class="form-group form-check">
196+
<input
197+
type="checkbox"
198+
class="form-check-input"
199+
id="termsCheckbox"
200+
required
201+
/>
202+
<label
203+
class="form-check-label"
204+
for="termsCheckbox"
205+
>I agree to the terms and conditions</label
206+
>
207+
</div>
117208
<div id="monext-component"></div>
118209
</div>
119210
</div>

0 commit comments

Comments
 (0)