up
This commit is contained in:
@@ -609,8 +609,8 @@ type dlocalPaymentListResp struct {
|
||||
}
|
||||
|
||||
// CheckDlocalPaymentByOrderID busca en la API de dLocal un pago con el order_id dado
|
||||
// y devuelve (pagado bool, paymentID string, error).
|
||||
func CheckDlocalPaymentByOrderID(cfg models.DlocalApi, orderID string) (bool, string, error) {
|
||||
// y devuelve (pagado bool, paymentID string, monto float64, payerEmail string, error).
|
||||
func CheckDlocalPaymentByOrderID(cfg models.DlocalApi, orderID string) (bool, string, float64, string, error) {
|
||||
baseURL := cfg.UrlDev
|
||||
accessKeyID := cfg.AccessKeyIDdev
|
||||
accessKeySecret := cfg.AccessKeySecretdev
|
||||
@@ -623,7 +623,7 @@ func CheckDlocalPaymentByOrderID(cfg models.DlocalApi, orderID string) (bool, st
|
||||
url := fmt.Sprintf("%s/v1/payments?order_id=%s", baseURL, orderID)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
return false, "", 0, "", err
|
||||
}
|
||||
authToken := fmt.Sprintf("Bearer %s:%s", accessKeyID, accessKeySecret)
|
||||
req.Header.Set("Authorization", authToken)
|
||||
@@ -632,16 +632,16 @@ func CheckDlocalPaymentByOrderID(cfg models.DlocalApi, orderID string) (bool, st
|
||||
client := &http.Client{Timeout: 15 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
return false, "", 0, "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
return false, "", 0, "", err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return false, "", fmt.Errorf("dlocal status %d: %s", resp.StatusCode, string(body))
|
||||
return false, "", 0, "", fmt.Errorf("dlocal status %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
// La respuesta puede ser lista o un objeto directo
|
||||
@@ -649,16 +649,16 @@ func CheckDlocalPaymentByOrderID(cfg models.DlocalApi, orderID string) (bool, st
|
||||
if err := json.Unmarshal(body, &list); err == nil && len(list.Data) > 0 {
|
||||
for _, p := range list.Data {
|
||||
if p.Status == "PAID" || p.Status == "AUTHORIZED" {
|
||||
return true, p.ID, nil
|
||||
return true, p.ID, p.Amount, p.Payer.Email, nil
|
||||
}
|
||||
}
|
||||
return false, "", nil
|
||||
return false, "", 0, "", nil
|
||||
}
|
||||
// Si no es lista, intentar objeto directo
|
||||
var single dlocalPaymentResp
|
||||
if err := json.Unmarshal(body, &single); err == nil && single.ID != "" {
|
||||
paid := single.Status == "PAID" || single.Status == "AUTHORIZED"
|
||||
return paid, single.ID, nil
|
||||
return paid, single.ID, single.Amount, single.Payer.Email, nil
|
||||
}
|
||||
return false, "", nil
|
||||
return false, "", 0, "", nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user