### Get Pix Key - Go Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/withdrawals/get_pix_key Example of how to call the Get Pix Key endpoint using Go. This is useful for backend services and microservices. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.payzu.com.br/v1/pix/withdrawals/keys/e1c21002-1b12-49e7-8c72-170000000000" req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println(err) return } req.Header.Set("accept", "application/json") req.Header.Set("authorization", "Bearer YOUR_API_KEY") client := &http.Client{} resp, err := client.Do(req) if err != nil { fmt.Println(err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Go SDK Installation Source: https://docs.payzu.com.br/docs/pix-processamento/sdks Install the PayZu Pix SDK for Go using go get. ```bash go get github.com/PayZuPlus/payzu-sdks/go ``` -------------------------------- ### GET Pix QRCode - Go Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/pix-operations/get_pix_qrcode Example of how to call the GET Pix QRCode endpoint using Go's net/http package. Useful for backend services. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.payzu.com.br/v1/pix/qrcode/1234567890" client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Authorization", "Bearer YOUR_API_KEY") req.Header.Set("Content-Type", "application/json") resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println("Response Status:", resp.Status) fmt.Println("Response Body:", string(body)) } ``` -------------------------------- ### Node.js SDK Example Source: https://docs.payzu.com.br/docs/pix-processamento/sdks Example of initializing the PayZu SDK in Node.js with payment details. Ensure you have the SDK installed via npm. ```javascript self.__next_f.push([1, "d:[", ["$", "span", null, {"style": {"--shiki-light": "#032F62", "--shiki-dark": "#9ECBFF"}, "children": "'amount'"}, {"$": "span", "style": {"--shiki-light": "#D73A49", "--shiki-dark": "#F97583"}, "children": " ="}, {"$": "span", null, {"style": {"--shiki-light": "#005CC5", "--shiki-dark": "#79B8FF"}, "children": " 99.90"}, {"$": "span", null, {"style": {"--shiki-light": "#24292E", "--shiki-dark": "#E1E4E8"}, "children": ","}}]]]) 89:["$", "span", null, {"className": "line", "children": [["$", "span", null, {"style": {"--shiki-light": "#032F62", "--shiki-dark": "#9ECBFF"}, "children": " 'clientReference'"}, {"$": "span", null, {"style": {"--shiki-light": "#D73A49", "--shiki-dark": "#F97583"}, "children": " ="}, {"$": "span", null, {"style": {"--shiki-light": "#032F62", "--shiki-dark": "#9ECBFF"}, "children": " 'order-1234'"}, {"$": "span", null, {"style": {"--shiki-light": "#24292E", "--shiki-dark": "#E1E4E8"}, "children": ","}}]]}] 8a:["$", "span", null, {"className": "line", "children": [["$", "span", null, {"style": {"--shiki-light": "#032F62", "--shiki-dark": "#9ECBFF"}, "children": " 'callbackUrl'"}, {"$": "span", null, {"style": {"--shiki-light": "#D73A49", "--shiki-dark": "#F97583"}, "children": " ="}, {"$": "span", null, {"style": {"--shiki-light": "#032F62", "--shiki-dark": "#9ECBFF"}, "children": " 'https://seusite.com.br/webhooks/payzu'"}, {"$": "span", null, {"style": {"--shiki-light": "#24292E", "--shiki-dark": "#E1E4E8"}, "children": ","}}]]}] 8b:["$", "span", null, {"className": "line", "children": ["$", "span", null, {"style": {"--shiki-light": "#24292E", "--shiki-dark": "#E1E4E8"}, "children": "])"}]}]} ``` -------------------------------- ### GET Pix QRCode - C# Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/pix-operations/get_pix_qrcode Example of how to call the GET Pix QRCode endpoint using C#'s HttpClient. Useful for .NET applications. ```csharp using System; using System.Net.Http; using System.Threading.Tasks; public class GetPixQRCode { public static async Task Main(string[] args) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY"); client.DefaultRequestHeaders.Add("Content-Type", "application/json"); string url = "https://api.payzu.com.br/v1/pix/qrcode/1234567890"; HttpResponseMessage response = await client.GetAsync(url); string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine($"Status Code: {response.StatusCode}"); Console.WriteLine($"Response Body: {responseBody}"); } } } ``` -------------------------------- ### Get User Summary Request Examples Source: https://docs.payzu.com.br/docs/conta-digital/gestao-de-conta/getUserSummary Examples of how to call the getUserSummary API using cURL, JavaScript, Go, Python, Java, and C#. These examples demonstrate different ways to structure the request. ```bash curl -X GET \ 'https://api.payzu.com.br/v1/summary?startDate=2023-01-01&endDate=2023-12-31&grouping=true' \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' ``` ```js fetch('https://api.payzu.com.br/v1/summary?startDate=2023-01-01&endDate=2023-12-31&grouping=true', { method: 'GET', headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "https://api.payzu.com.br/v1/summary?startDate=2023-01-01&endDate=2023-12-31&grouping=true" req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Authorization", "Bearer YOUR_ACCESS_TOKEN") client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` ```python import requests url = "https://api.payzu.com.br/v1/summary?startDate=2023-01-01&endDate=2023-12-31&grouping=true" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN" } response = requests.get(url, headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") ``` ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class GetUserSummary { public static void main(String[] args) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.payzu.com.br/v1/summary?startDate=2023-01-01&endDate=2023-12-31&grouping=true")) .header("Authorization", "Bearer YOUR_ACCESS_TOKEN") .GET() .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` ```csharp using System; using System.Net.Http; using System.Threading.Tasks; public class GetUserSummary { public static async Task Main(string[] args) { using (var client = new HttpClient()) { var request = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri("https://api.payzu.com.br/v1/summary?startDate=2023-01-01&endDate=2023-12-31&grouping=true") }; request.Headers.Add("Authorization", "Bearer YOUR_ACCESS_TOKEN"); var response = await client.SendAsync(request); var responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } } } ``` -------------------------------- ### GET Pix QRCode - Java Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/pix-operations/get_pix_qrcode Example of how to call the GET Pix QRCode endpoint using Java's HttpClient. Suitable for enterprise applications. ```java import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.io.IOException; public class GetPixQRCode { public static void main(String[] args) { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.payzu.com.br/v1/pix/qrcode/1234567890")) .header("Authorization", "Bearer YOUR_API_KEY") .header("Content-Type", "application/json") .GET() .build(); try { HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println("Status Code: " + response.statusCode()); System.out.println("Response Body: " + response.body()); } catch (IOException | InterruptedException e) { e.printStackTrace(); } } } ``` -------------------------------- ### cURL Request Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/callbacks/get_user_callbacks This example shows how to make a GET request to the /user/callbacks endpoint using cURL. Ensure you include the 'Content-Type' header. ```bash curl -X GET "https://api.payzu.processamento.com/v1/user/callbacks" \ -H "Content-Type: application/json" ``` -------------------------------- ### PHP SDK Usage Example (Configuration) Source: https://docs.payzu.com.br/docs/pix-processamento/sdks Initial configuration setup for the PHP SDK. This snippet shows how to set the host for the API. ```php setHost('https://api.payzu.processamento.com/v1') ``` -------------------------------- ### Send Pix Request Example Source: https://docs.payzu.com.br/docs/pix-processamento/tutoriais/send-pix This Python snippet demonstrates how to make a GET request to the Pix key endpoint. Ensure you have the 'requests' library installed. ```python res = requests.get( 'https://api.payzu.processamento.com/v1/pix/key', params = { 'key': 'joao@example.com' }, headers = { 'Authorization': f'Bearer {token}' } ) ``` -------------------------------- ### Webhook Setup Steps Source: https://docs.payzu.com.br/docs/pix-processamento/webhooks A step-by-step guide to implementing PayZUPix webhooks. This includes creating a public endpoint, passing the URL in the transaction request, and implementing the handler. ```markdown 1. Crie um endpoint público no seu servidor Algum lugar acessível pela internet que aceite POST com JSON. Exemplos: `https://seusite.com.br/webhooks/payzu`, `https://api.suaempresa.com/payzu/callback`. Durante desenvolvimento local, use túneis como `ngrok` ou `localtunnel` pra expor o `localhost`. 2. Passe a URL ao criar a transação Em todo `POST /pix`, `POST /withdraw`, `POST /internal-transfer`, inclua o campo `callbackUrl`. Pode ser a mesma URL pra todos. 3. Implemente o handler Receba o POST, leia o JSON, processe e responda `2xx` em até 5 segundos. Veja exemplos em `docs.payzu.com.br/docs/pix-processamento/webhooks.c7`. ``` -------------------------------- ### Get Pix Key - C# Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/withdrawals/get_pix_key Example of how to call the Get Pix Key endpoint using C#. This is useful for .NET applications. ```csharp using System; using System.Net.Http; using System.Threading.Tasks; public class GetPixKey { public static async Task Main(string[] args) { using (var client = new HttpClient()) { var request = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri("https://api.payzu.com.br/v1/pix/withdrawals/keys/e1c21002-1b12-49e7-8c72-170000000000") }; request.Headers.Add("accept", "application/json"); request.Headers.Add("authorization", "Bearer YOUR_API_KEY"); HttpResponseMessage response = await client.SendAsync(request); string responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } } } ``` -------------------------------- ### Example Request (Go) Source: https://docs.payzu.com.br/docs/conta-digital/depositos/getTransactionProof Example of how to request a transaction proof using Go's net/http package. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { client := &http.Client{} req, err := http.NewRequest("GET", "https://payzu.com.br/api/v1/transactions/proof/12345", nil) if err != nil { fmt.Println(err) return } req.Header.Add("Accept", "application/json") resp, err := client.Do(req) if err != nil { fmt.Println(err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get Pix Key - Python Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/withdrawals/get_pix_key Example of how to call the Get Pix Key endpoint using Python. This is useful for scripting and backend development. ```python import requests url = "https://api.payzu.com.br/v1/pix/withdrawals/keys/e1c21002-1b12-49e7-8c72-170000000000" headers = { "accept": "application/json", "authorization": "Bearer YOUR_API_KEY" } response = requests.get(url, headers=headers) print(response.json()) ``` -------------------------------- ### Go Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/reports/list_user_reports Example of how to call the List User Reports endpoint using Go's net/http package. ```go package main import ( "fmt" "io/ioutil" "net/http" ) func main() { client := &http.Client{} req, err := http.NewRequest("GET", "https://api.payzu.com.br/v1/reports", nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("Authorization", "Bearer YOUR_ACCESS_TOKEN") res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Get Pix Key - cURL Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/withdrawals/get_pix_key Example of how to call the Get Pix Key endpoint using cURL. This is useful for quick testing and integration. ```bash curl --request GET \ --url https://api.payzu.com.br/v1/pix/withdrawals/keys/e1c21002-1b12-49e7-8c72-170000000000 \ --header 'accept: application/json' \ --header 'authorization: Bearer YOUR_API_KEY' ``` -------------------------------- ### Go SDK Usage Example Source: https://docs.payzu.com.br/docs/pix-processamento/sdks Example of creating a Pix charge using the Go SDK. Ensure your PAYZU_TOKEN is set as an environment variable. ```go import ( "context" "os" payzupix "github.com/PayZuPlus/payzu-sdks/go" ) cfg := payzupix.NewConfiguration() cfg.Servers = payzupix.ServerConfigurations{{URL: "https://api.payzu.processamento.com/v1"}} client := payzupix.NewAPIClient(cfg) ctx := context.WithValue(context.Background(), payzupix.ContextAccessToken, os.Getenv("PAYZU_TOKEN")) req := payzupix.PostPixRequest{ Amount: 99.90, ClientReference: payzupix.PtrString("order-1234"), CallbackUrl: payzupix.PtrString("https://seusite.com.br/webhooks/payzu"), } charge, _, err := client.PixOperationsAPI.PostPix(ctx).PostPixRequest(req).Execute() ``` -------------------------------- ### GET Pix QRCode - cURL Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/pix-operations/get_pix_qrcode Example of how to call the GET Pix QRCode endpoint using cURL. This is useful for quick testing and integration. ```bash curl --location --request GET 'https://api.payzu.com.br/v1/pix/qrcode/1234567890' \ --header 'Authorization: Bearer YOUR_API_KEY' \ --header 'Content-Type: application/json' ``` -------------------------------- ### Get Pix Key - Java Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/withdrawals/get_pix_key Example of how to call the Get Pix Key endpoint using Java. This is useful for enterprise applications and Android development. ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class GetPixKey { public static void main(String[] args) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.payzu.com.br/v1/pix/withdrawals/keys/e1c21002-1b12-49e7-8c72-170000000000")) .header("accept", "application/json") .header("authorization", "Bearer YOUR_API_KEY") .GET() .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` -------------------------------- ### Example Request (Java) Source: https://docs.payzu.com.br/docs/conta-digital/depositos/getTransactionProof Example of how to request a transaction proof using Java's OkHttp library. ```java import okhttp3.*; import java.io.IOException; public class GetTransactionProof { public static void main(String[] args) throws IOException { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://payzu.com.br/api/v1/transactions/proof/12345") .header("Accept", "application/json") .build(); try (Response response = client.newCall(request).execute()) { if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); System.out.println(response.body().string()); } } } ``` -------------------------------- ### Get Pix Key - JavaScript Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/withdrawals/get_pix_key Example of how to call the Get Pix Key endpoint using JavaScript. This is useful for web applications and Node.js environments. ```javascript const url = 'https://api.payzu.com.br/v1/pix/withdrawals/keys/e1c21002-1b12-49e7-8c72-170000000000'; const headers = { 'accept': 'application/json', 'authorization': 'Bearer YOUR_API_KEY' }; fetch(url, { method: 'GET', headers: headers }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### C# Request Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/reports/get_user_transactions Example of how to make a request to the get user transactions endpoint using C#. This snippet shows how to perform an HTTP GET request. ```csharp using System; using System.Net.Http; using System.Threading.Tasks; public class GetTransactions { public static async Task Main(string[] args) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_KEY"); var response = await client.GetAsync("https://api.payzu.com.br/v1/transactions"); response.EnsureSuccessStatusCode(); // Throw if not 2xx var responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } } } ``` -------------------------------- ### Java Request Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/reports/get_user_transactions Example of how to make a request to the get user transactions endpoint using Java. This snippet demonstrates making an HTTP GET request. ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class GetTransactions { public static void main(String[] args) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.payzu.com.br/v1/transactions")) .header("accept", "application/json") .header("authorization", "Bearer YOUR_API_KEY") .GET() .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` -------------------------------- ### Initialize Production Logger in Go (Zap) Source: https://docs.payzu.com.br/docs/pix-processamento/best-practices/security Demonstrates how to initialize a production-ready logger using the Zap library in Go. This is useful for structured logging in high-traffic applications. ```go logger, _ := zap.NewProduction() defers, _ := logger.Sync() // flushes buffer, if any logger.Info("User logged in", // Structured context as strongly typed fields, zap.String("ID", "12345"), zap.Duration("took", time.Nanosecond), ) ``` -------------------------------- ### API Request Examples (cURL, JavaScript, Go, Python, Java, C#) Source: https://docs.payzu.com.br/docs/conta-digital/depositos/createPixCharge Examples of how to make a request to create a Pix charge using different programming languages. These snippets demonstrate the common structure for initiating a Pix charge. ```bash curl -X POST \ http://localhost:3000/v1/pix/charge \ -H 'Content-Type: application/json' \ -d '{ "amount": "10.00", "description": "Pagamento de boleto" }' ``` ```js fetch('http://localhost:3000/v1/pix/charge', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ amount: '10.00', description: 'Pagamento de boleto' }) }).then(response => response.json()) .then(data => console.log(data)); ``` ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { payload := map[string]string{ "amount": "10.00", "description": "Pagamento de boleto" } jsonPayload, _ := json.Marshal(payload) resp, err := http.Post("http://localhost:3000/v1/pix/charge", "application/json", bytes.NewBuffer(jsonPayload)) if err != nil { fmt.Println(err) return } defer resp.Body.Close() var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) fmt.Println(result) } ``` ```python import requests url = "http://localhost:3000/v1/pix/charge" payload = { "amount": "10.00", "description": "Pagamento de boleto" } headers = { "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; public class PixCharge { public static void main(String[] args) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("http://localhost:3000/v1/pix/charge")) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString( "{\"amount\": \"10.00\", \"description\": \"Pagamento de boleto\"}" )) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } } ``` ```csharp using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; public class PixCharge { public static async Task Main(string[] args) { using (var client = new HttpClient()) { var payload = new { amount = "10.00", description = "Pagamento de boleto" }; var jsonPayload = System.Text.Json.JsonSerializer.Serialize(payload); var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); var response = await client.PostAsync("http://localhost:3000/v1/pix/charge", content); var responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } } } ``` -------------------------------- ### Go Request Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/reports/get_user_transactions Example of how to make a request to the get user transactions endpoint using Go. This snippet illustrates making HTTP GET requests in Go. ```go package main import ( "fmt" "net/http" "io/ioutil" ) func main() { client := &http.Client{} req, err := http.NewRequest("GET", "https://api.payzu.com.br/v1/transactions", nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("accept", "application/json") req.Header.Add("authorization", "Bearer YOUR_API_KEY") resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Setting up API Request Headers Source: https://docs.payzu.com.br/docs/pix-processamento/best-practices/pagination Demonstrates how to set up essential headers for an API request, including Content-Type and authorization. Ensure your token is correctly formatted. ```javascript const headers = { 'Content-Type': 'application/json' }; ``` -------------------------------- ### Java Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/reports/list_user_reports Example of how to call the List User Reports endpoint using Java's HttpClient. ```java import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.io.IOException; public class ListReports { public static void main(String[] args) { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://api.payzu.com.br/v1/reports")) .header("Authorization", "Bearer YOUR_ACCESS_TOKEN") .GET() .build(); try { HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); } catch (IOException | InterruptedException e) { e.printStackTrace(); } } } ``` -------------------------------- ### GET Pix QRCode - Python Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/pix-operations/get_pix_qrcode Example of how to call the GET Pix QRCode endpoint using Python's requests library. Ideal for backend integrations. ```python import requests url = "https://api.payzu.com.br/v1/pix/qrcode/1234567890" headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" } response = requests.get(url, headers=headers) print(f"Status Code: {response.status_code}") print(f"Response Body: {response.json()}") ``` -------------------------------- ### Java Example for POST /infractions/defense Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/infractions/post_infractions_defense Demonstrates submitting a defense using Java. It includes POJOs for request/response bodies and uses a common HTTP client library. ```java import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.List; public class DefenseSubmission { // Define POJOs for request and response bodies static class Document { public String name; public String url; } static class DefenseDetails { public String description; public List documents; } static class DefenseRequest { public String infractionId; public DefenseDetails defense; } static class DefenseResponse { public String message; public String defenseId; } public static void main(String[] args) throws IOException, InterruptedException { HttpClient client = HttpClient.newHttpClient(); String url = "http://your-api-url/infractions/defense"; // Create request body DefenseRequest requestBody = new DefenseRequest(); requestBody.infractionId = "inf-12345"; requestBody.defense = new DefenseDetails(); requestBody.defense.description = "The vehicle was parked legally."; requestBody.defense.documents = List.of(new Document() {{ name = "parking_receipt.pdf"; url = "http://example.com/docs/parking_receipt.pdf"; }}); // Serialize request body to JSON String requestJson = new com.fasterxml.jackson.databind.ObjectMapper().writeValueAsString(requestBody); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(url)) .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(requestJson)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println("Status Code: " + response.statusCode()); System.out.println("Response Body: " + response.body()); // Handle response if (response.statusCode() == 200) { DefenseResponse defenseResponse = new com.fasterxml.jackson.databind.ObjectMapper().readValue(response.body(), DefenseResponse.class); System.out.println("Defense submitted successfully: " + defenseResponse.message + " (ID: " + defenseResponse.defenseId + ")"); } else { System.err.println("Failed to submit defense."); } } } ``` -------------------------------- ### C# Example for POST /infractions/defense Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/infractions/post_infractions_defense Provides a C# example using `HttpClient` to submit a defense. It defines request/response models and demonstrates making the POST request. ```csharp using System; using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading.Tasks; public class DefenseSubmission { public class Document { public string Name { get; set; } public string Url { get; set; } } public class DefenseDetails { public string Description { get; set; } public List Documents { get; set; } } public class DefenseRequest { public string InfractionId { get; set; } public DefenseDetails Defense { get; set; } } public class DefenseResponse { public string Message { get; set; } public string DefenseId { get; set; } } public static async Task Main(string[] args) { using (var httpClient = new HttpClient()) { var url = "http://your-api-url/infractions/defense"; var requestBody = new DefenseRequest { InfractionId = "inf-12345", Defense = new DefenseDetails { Description = "The vehicle was parked legally.", Documents = new List { new Document { Name = "parking_receipt.pdf", Url = "http://example.com/docs/parking_receipt.pdf" } } } }; var jsonPayload = JsonSerializer.Serialize(requestBody); var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); try { var response = await httpClient.PostAsync(url, content); if (response.IsSuccessStatusCode) { var responseStream = await response.Content.ReadAsStreamAsync(); var defenseResponse = await JsonSerializer.DeserializeAsync(responseStream); Console.WriteLine($"Defense submitted successfully: {defenseResponse.Message} (ID: {defenseResponse.DefenseId})"); } else { var errorContent = await response.Content.ReadAsStringAsync(); Console.WriteLine($"Failed to submit defense. Status code: {response.StatusCode}. Response: {errorContent}"); } } catch (HttpRequestException e) { Console.WriteLine($"An error occurred: {e.Message}"); } } } } ``` -------------------------------- ### GET Pix QRCode - JavaScript Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/pix-operations/get_pix_qrcode Example of how to call the GET Pix QRCode endpoint using JavaScript's fetch API. Suitable for web applications. ```js const url = "https://api.payzu.com.br/v1/pix/qrcode/1234567890"; const headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" }; fetch(url, { method: "GET", headers: headers }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Infractions Endpoint Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/infractions/get_infractions This example demonstrates how to call the Get Infractions endpoint to retrieve a list of infractions. It includes common query parameters for filtering and pagination. ```javascript const getInfractions = async (params) => { const response = await fetch('/pix/v1/infractions', { method: 'GET', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer YOUR_API_KEY' }, params: params }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); }; // Example usage: getInfractions({ dateFrom: '2023-01-01', dateTo: '2023-12-31', status: 'pending' }).then(data => { console.log(data); }).catch(error => { console.error('Error fetching infractions:', error); }); ``` -------------------------------- ### Example Request (C#) Source: https://docs.payzu.com.br/docs/conta-digital/depositos/getTransactionProof Example of how to request a transaction proof using C#'s HttpClient. ```csharp using System; using System.Net.Http; using System.Threading.Tasks; public class GetTransactionProof { public static async Task Main(string transactionId) { using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var response = await client.GetAsync($"https://payzu.com.br/api/v1/transactions/proof/{transactionId}"); response.EnsureSuccessStatusCode(); var responseBody = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseBody); } } } ``` -------------------------------- ### cURL Request Example for GET Pix Key Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/withdrawals/get_pix_key This example demonstrates how to make a GET request to the Pix Key endpoint using cURL. It shows the basic structure of the request. ```bash curl \ --request GET \ --url 'https://api.payzu.com.br/pix/keys/YOUR_PIX_KEY' \ --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' ``` -------------------------------- ### Initialize PayZu Pix Configuration (Go) Source: https://docs.payzu.com.br/docs/pix-processamento/sdks Demonstrates how to initialize the PayZu Pix configuration in Go. This is typically the first step before making any Pix-related calls. ```go cfg := payzupix.NewConfiguration() cfg.BasePath = "https://api.payzu.com.br" client := payzupix.NewAPIClient(cfg) ``` -------------------------------- ### Get Infractions Example Source: https://docs.payzu.com.br/docs/pix-processamento/endpoints/infractions/get_infractions This example demonstrates how to make a GET request to the /infractions endpoint to retrieve a list of all infractions. The response includes details such as the infraction type, who reported it, and the specific report details. ```javascript { "statusCode": 200, "data": [ { "type": "FRAUD", "reportedBy": "DEBITED_PARTICIPANT", "reportDetails": "Transação não autorizada", "analysisResult": null, "analysisDetails": null } ] } ``` -------------------------------- ### Initialize PayZu Pix Configuration (PHP) Source: https://docs.payzu.com.br/docs/pix-processamento/sdks Shows how to set up the PayZu Pix configuration in PHP. Ensure you have the necessary configuration object before proceeding. ```php setHost('https://api.payzu.com.br'); $apiClient = new ```