Skip to content

Commit

Permalink
Update bnpl approve response
Browse files Browse the repository at this point in the history
  • Loading branch information
abalikci committed Feb 24, 2025
1 parent 07999c9 commit ab90cb3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 5 deletions.
10 changes: 5 additions & 5 deletions adapter/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,20 +553,20 @@ func (api *Payment) InitBnplPayment(ctx context.Context, request InitBnplPayment
return response.Data, nil
}

func (api *Payment) ApproveBnplPayment(ctx context.Context, paymentId int64) error {
func (api *Payment) ApproveBnplPayment(ctx context.Context, paymentId int64) (*PaymentResponse, error) {

newRequest, err := api.Client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("/payment/v1/bnpl-payments/%d/approve", paymentId), nil)
if err != nil {
return err
return nil, err
}

response := &Void{}
response := &Response[PaymentResponse]{}
err = api.Client.Do(ctx, newRequest, response)
if err != nil {
return err
return nil, err
}

return nil
return response.Data, nil
}

func (api *Payment) RetrieveActiveBanks(ctx context.Context) (*InstantTransferBanksResponse, error) {
Expand Down
79 changes: 79 additions & 0 deletions adapter/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package adapter

import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
"io/ioutil"
"log"
"os"
)

type Cryptogram struct {
PublicKey []byte
}

// NewCryptogram конструктор
func NewCryptogram(path string) *Cryptogram {
public, err := ioutil.ReadFile(path)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

return &Cryptogram{
PublicKey: public,
}
}

// EncryptWithPublicKey encrypts data with public key
func (c *Cryptogram) EncryptWithPublicKey(msg []byte) (mes []byte, err error) {

rawPem, err := ioutil.ReadFile("rsa_prod.rsa")

pemBlock, _ := pem.Decode(rawPem)
publicKey, err := x509.ParsePKIXPublicKey(pemBlock.Bytes)

/*block, _ := pem.Decode(c.PublicKey)
if block == nil {
panic("failed to parse PEM block containing the public key")
}
pub, err := x509.ParsePKCS1PublicKey(block.Bytes)
if err != nil {
panic("failed to parse DER encoded public key: " + err.Error())
}*/

/*block, _ := pem.Decode(c.PublicKey)
if block == nil {
fmt.Println("error 1")
return nil,errors.New("private key error!")
}
pub, err := x509.ParsePKCS1PublicKey(block.Bytes)
if err != nil {
fmt.Println("error 2")
return nil, err
}*/
mes, err = rsa.EncryptPKCS1v15(rand.Reader, publicKey.(*rsa.PublicKey), msg)
if err != nil {
log.Fatal(err)
}
return
}

func adapter() {

Cryptogram := NewCryptogram("rsa_prod.rsa")
b, err := Cryptogram.EncryptWithPublicKey([]byte("{\"hpan\": \"ххххх\",\"cvc\":\"хххх\",\"expDate\":\"хххх\",\"terminalId\":\"хххххххх\"}"))
if err != nil {
fmt.Println(err.Error())
return
}

s := base64.StdEncoding.EncodeToString(b)
fmt.Println(s)

}

0 comments on commit ab90cb3

Please sign in to comment.