Skip to content

Commit 1301a2d

Browse files
Jose CalderonJose Calderon
Jose Calderon
authored and
Jose Calderon
committed
ajustes
1 parent e7ca16e commit 1301a2d

File tree

8 files changed

+119
-68
lines changed

8 files changed

+119
-68
lines changed

Diff for: 2go.mod

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module demoCulqi
2+
3+
go 1.16
4+
5+
require (
6+
github.com/culqi/culqi-go v0.0.0-20230711013133-717467511191 // indirect
7+
github.com/go-chi/chi v1.5.4
8+
)

Diff for: README.md

+34-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,41 @@ La demo integra Culqi Go, Checkout V4 , Culqi 3DS y es compatible con la v2.0 de
1414

1515
> Recuerda que las credenciales son enviadas al correo que registraste en el proceso de afiliación.
1616
17-
## Configuración
17+
## Configuración backend
1818

19-
Dentro del archivo **main.go** coloca tus llaves pk y sk.
19+
Primero se tiene que modificar los valores del archivo `config/config.go` que se encuentra en al raíz del proyecto. A continuación un ejemplo.
20+
21+
```
22+
var pk string = " Llave pública del comercio (pk_test_xxxxxxxxx)"
23+
var sk string = "Llave secreta del comercio (sk_test_xxxxxxxxx)"
24+
var puerto string = ":3000"
25+
var encrypt = "0" // 1 = activar encriptación
26+
var encryptiondData = []byte(`{
27+
"rsa_public_key": "Llave pública RSA que sirve para encriptar el payload de los servicios",
28+
"rsa_id": "Id de la llave RSA"
29+
}`)
30+
```
31+
## Configuración frontend
32+
33+
Para configurar los datos del cargo, pk del comercio y datos del cliente se tiene que modificar en el archivo `js/config/index.js`.
34+
35+
```js
36+
export default Object.freeze({
37+
TOTAL_AMOUNT: monto de pago,
38+
CURRENCY: tipo de moneda,
39+
PUBLIC_KEY: llave publica del comercio (pk_test_xxxxx),
40+
RSA_ID: Id de la llave RSA,
41+
RSA_PUBLIC_KEY: Llave pública RSA que sirve para encriptar el payload de los servicios del checkout,
42+
COUNTRY_CODE: iso code del país(Ejemplo PE)
43+
});
44+
45+
export const customerInfo = {
46+
firstName: "Fernando",
47+
lastName: "Chullo",
48+
address: "Coop. Villa el Sol",
49+
phone: "945737476",
50+
}
51+
```
2052

2153
## Inicializar la demo
2254

Diff for: config/config.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package config
2+
3+
import (
4+
//"testing"
5+
culqi "github.com/culqi/culqi-go"
6+
)
7+
8+
const pk string = "pk_test_e94078b9b248675d"
9+
const sk string = "sk_test_c2267b5b262745f0"
10+
const rsa_id = "de35e120-e297-4b96-97ef-10a43423ddec"
11+
const rsa_public_key = "-----BEGIN PUBLIC KEY-----\n" +
12+
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDswQycch0x/7GZ0oFojkWCYv+gr5CyfBKXc3Izq+btIEMCrkDrIsz4Lnl5E3FSD7/htFn1oE84SaDKl5DgbNoev3pMC7MDDgdCFrHODOp7aXwjG8NaiCbiymyBglXyEN28hLvgHpvZmAn6KFo0lMGuKnz8HiuTfpBl6HpD6+02SQIDAQAB\n" +
13+
"-----END PUBLIC KEY-----"
14+
15+
var Puerto string = ":3000"
16+
17+
const Encrypt = "1"
18+
19+
var EncryptionData = []byte(`{}`)
20+
21+
var (
22+
publicKey, secretKey string
23+
encryptionData []byte
24+
encrypt string
25+
)
26+
27+
func init() {
28+
culqi.Key(pk, sk)
29+
30+
EncryptionData = []byte(`{
31+
"rsa_public_key": "` + rsa_public_key + `",
32+
"rsa_id": "` + rsa_id + `"
33+
}`)
34+
}

Diff for: go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
module demoCulqi
1+
module culqi-go-demo
22

3-
go 1.16
3+
go 1.19
44

55
require (
6-
github.com/culqi/culqi-go v0.0.0-20230711013133-717467511191 // indirect
6+
github.com/culqi/culqi-go v0.0.0-20230711013133-717467511191
77
github.com/go-chi/chi v1.5.4
88
)

Diff for: js/config/checkout.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const culqiConfig = (jsonParams) => {
99
order: jsonParams.orderId,
1010
currency: config.CURRENCY,
1111
description: "Polo/remera Culqi lover",
12-
amount: config.TOTAL_AMOUNT,
12+
amount: jsonParams.amount,
1313
xculqirsaid: config.RSA_ID,
1414
rsapublickey: config.RSA_PUBLIC_KEY,
1515
excludencryptoperations: [''],
@@ -32,7 +32,7 @@ const culqiConfig = (jsonParams) => {
3232
buttonBackground: "", // hexadecimal
3333
menuColor: "", // hexadecimal
3434
linksColor: "", // hexadecimal
35-
buttonText: "", // texto que tomará el botón
35+
buttonText: jsonParams.buttonTex, // texto que tomará el botón
3636
buttonTextColor: "", // hexadecimal
3737
priceColor: "", // hexadecimal
3838
},

Diff for: js/main.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ let jsonParams = {
1818

1919
async function generarOrder(){
2020
const { statusCode, data } = await generateOrderImpl();
21-
console.log("hola",data);
2221
if (statusCode === 201) {
2322
console.log("Order",data);
2423
return data.id;
@@ -114,17 +113,17 @@ window.culqi = async () => {
114113
statusCode = responseCard.statusCode;
115114
}
116115
if (statusCode === 200) {
117-
if(objResponse.action_code === "REVIEW"){
118-
validationInit3DS({ email, statusCode, tokenId });
119-
}else{
120-
$("#response_card").text("ERROR AL REALIZAR LA OPERACIÓN");
121-
}
116+
if(objResponse.action_code === "REVIEW"){
117+
validationInit3DS({ email, statusCode, tokenId });
118+
}else{
119+
$("#response_card").text("ERROR AL REALIZAR LA OPERACIÓN");
120+
}
122121
} else if (statusCode === 201) {
123-
$("#response_card").text("OPERACIÓN EXITOSA - SIN 3DS");
124-
Culqi3DS.reset();
125-
} else {
126-
$("#response_card").text("OPERACIÓN FALLIDA - SIN 3DS");
122+
$("#response_card").text("OPERACIÓN EXITOSA - SIN 3DS");
127123
Culqi3DS.reset();
124+
} else {
125+
$("#response_card").text("OPERACIÓN FALLIDA - SIN 3DS");
126+
Culqi3DS.reset();
128127
}
129128
} else {
130129
console.log(Culqi.error);

Diff for: js/services/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Service {
2828
success: function (data, status, xhr) {
2929
statusCode = xhr.status;
3030
//response = data;
31-
console.log('xhr.status',xhr.status);
3231
}
3332
});
3433
console.log('statusCode',statusCode);
@@ -52,7 +51,7 @@ class Service {
5251
};
5352

5453
createCard = async (bodyCard) => {
55-
return this.#http2({ endPoint: "generateCards", body: bodyCard });
54+
return this.#http2({ endPoint: "generateCard", body: bodyCard });
5655
};
5756
}
5857

Diff for: main.go

+28-49
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"encoding/json"
54
"errors"
65
"fmt"
76
"io/ioutil"
@@ -14,18 +13,9 @@ import (
1413

1514
"github.com/culqi/culqi-go"
1615
"github.com/go-chi/chi"
17-
)
1816

19-
var pk string = "pk_test_e94078b9b248675d"
20-
var sk string = "sk_test_c2267b5b262745f0"
21-
var puerto string = ":3000"
22-
var encrypt = "0"
23-
var encryptiondData = []byte(`{
24-
"rsa_public_key": "-----BEGIN PUBLIC KEY-----
25-
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYR6Oqz+vX2amSnNzPosH1CIMocGnHCnxlr1RuRyYtrAAVv3oxpSx42R9KIbW3yBfWwFxpU9m1us1ZjPmISRmjy64z6q6rv5UZNOWllM5v2A+F2MceWHRIJYOxIwV9oAx36EH89qOEnOekVLqZhkdrAx2LvLfqGprKsDcfX06urwIDAQAB
26-
-----END PUBLIC KEY-----",
27-
"rsa_id": "f355d27f-e735-46a7-b8bd-9773357ff034"
28-
}`)
17+
config "culqi-go-demo/config"
18+
)
2919

3020
func main() {
3121
r := chi.NewRouter()
@@ -42,22 +32,11 @@ func main() {
4232
//http.HandleFunc("/index-card", homePageHandler)
4333
r.Get("/index-card", homePageHandler)
4434
r.Get("/", homePage2Handler)
45-
r.Post("/culqi/generateCards", cardsPageHandler)
35+
r.Post("/culqi/generateCard", cardsPageHandler)
4636
r.Post("/culqi/generateCustomer", customerPageHandler)
4737
r.Post("/culqi/generateCharge", chargePageHandler)
4838
r.Post("/culqi/generateOrder", orderPageHandler)
49-
r.Get("/admin", adminPageHandler)
50-
http.ListenAndServe(puerto, r)
51-
}
52-
53-
type Customers struct {
54-
FirstName string `json:"first_name"`
55-
LastName string `json:"last_name"`
56-
Email string `json:"email"`
57-
Address string `json:"address"`
58-
AddressCity string `json:"address_city"`
59-
CountryCode string `json:"country_code"`
60-
PhoneNumber string `json:"phone_number"`
39+
http.ListenAndServe(config.Puerto, r)
6140
}
6241

6342
func homePageHandler(w http.ResponseWriter, r *http.Request) {
@@ -70,15 +49,13 @@ func homePage2Handler(w http.ResponseWriter, r *http.Request) {
7049
template.Execute(w, nil)
7150
}
7251

73-
func adminPageHandler(w http.ResponseWriter, r *http.Request) {
74-
w.Write([]byte("This is admin page"))
75-
}
52+
// Consumo de servicios
7653
func cardsPageHandler(w http.ResponseWriter, r *http.Request) {
7754
reqBody, _ := ioutil.ReadAll(r.Body)
7855

79-
culqi.Key(pk, sk)
80-
if encrypt == "1" {
81-
statusCode, res, _ := culqi.CreateCard(reqBody, encryptiondData...)
56+
//culqi.Key(pk, sk)
57+
if config.Encrypt == "1" {
58+
statusCode, res, _ := culqi.CreateCard(reqBody, config.EncryptionData...)
8259
fmt.Println(statusCode)
8360
fmt.Println(res)
8461
w.Header().Set("Content-Type", "application/json")
@@ -98,10 +75,10 @@ func chargePageHandler(w http.ResponseWriter, r *http.Request) {
9875
reqBody, _ := ioutil.ReadAll(r.Body)
9976
log.Printf("error decoding sakura response: %v", reqBody)
10077

101-
culqi.Key(pk, sk)
78+
//culqi.Key(pk, sk)
10279

103-
if encrypt == "1" {
104-
statusCode, res, _ := culqi.CreateCharge(reqBody, encryptiondData...)
80+
if config.Encrypt == "1" {
81+
statusCode, res, _ := culqi.CreateCharge(reqBody, config.EncryptionData...)
10582
fmt.Println(statusCode)
10683
fmt.Println(res)
10784
w.Header().Set("Content-Type", "application/json")
@@ -119,15 +96,24 @@ func chargePageHandler(w http.ResponseWriter, r *http.Request) {
11996

12097
}
12198
func customerPageHandler(w http.ResponseWriter, r *http.Request) {
122-
reqBody, _ := ioutil.ReadAll(r.Body)
123-
var post Customers
124-
json.Unmarshal(reqBody, &post)
12599

126-
culqi.Key(pk, sk)
100+
fmt.Println(r.Body)
101+
reqBody, err := ioutil.ReadAll(r.Body)
102+
if err != nil {
103+
log.Fatal(err)
104+
}
105+
bodyString := string(reqBody)
106+
fmt.Println(bodyString)
107+
log.Printf("error decoding sakura response: %v", reqBody)
108+
109+
//culqi.Key(pk, sk)
127110

128111
statusCode, res, err := culqi.CreateCustomer(reqBody)
129-
fmt.Println(statusCode)
130112
fmt.Println(err)
113+
fmt.Println("statusCode")
114+
fmt.Println(statusCode)
115+
fmt.Println(res)
116+
131117
w.Header().Set("Content-Type", "application/json")
132118
w.WriteHeader(statusCode)
133119
w.Write([]byte(res))
@@ -143,22 +129,15 @@ func orderPageHandler(w http.ResponseWriter, r *http.Request) {
143129
fmt.Println(bodyString)
144130
log.Printf("error decoding sakura response: %v", reqBody)
145131

146-
culqi.Key(pk, sk)
132+
//culqi.Key(pk, sk)
147133

148-
statusCode, res, err := culqi.CreateOrder(reqBody)
134+
statusCode, res, err := culqi.CreateOrder(reqBody, config.EncryptionData...)
149135
fmt.Println(err)
150136
fmt.Println("statusCode")
151137
fmt.Println(statusCode)
152138
fmt.Println(res)
153139

154140
w.Header().Set("Content-Type", "application/json")
155-
//code, _ := strconv.Atoi(statusCode)
156141
w.WriteHeader(statusCode)
157-
w.Write([]byte(res)) /*
158-
jsonData, err := json.Marshal(res)
159-
w.Write(jsonData)
160-
fmt.Println(jsonData)*/
161-
//json.NewDecoder(w).Decode(res)
162-
//json.NewEncoder(w).Encode(res)
163-
142+
w.Write([]byte(res))
164143
}

0 commit comments

Comments
 (0)