### Get QR Code Content for Short Payment Descriptor (Go) Source: https://github.com/dundee/qrpay/blob/master/README.md Retrieves the string content for a QR code representing a payment in the Short Payment Descriptor format. Requires setting the IBAN and amount. The function returns the formatted string, which can be used for generating QR codes without image output. ```Go import "github.com/dundee/qrpay" import "fmt" p := qrpay.NewSpaydPayment() p.SetIBAN("CZ5855000000001265098001") p.SetAmount("108") fmt.Println(qrpay.GenerateString()) // Output: SPD*1.0*ACC:CZ5855000000001265098001*AM:108* ``` -------------------------------- ### Set Payment Amount and Currency (Go) Source: https://context7.com/dundee/qrpay/llms.txt Demonstrates how to set the payment amount and currency for both SPAYD and EPC payment formats using the qrpaysdk. It includes error handling for validation and supports both decimal and integer amount representations. Requires 'github.com/dundee/qrpay'. ```go package main import ( "fmt" "github.com/dundee/qrpay" ) func main() { payment := qrpay.NewSpaydPayment() payment.SetIBAN("CZ5855000000001265098001") payment.SetRecipientName("Merchant Store") // Set amount as string (decimal format) err := payment.SetAmount("1234.56") if err != nil { fmt.Printf("Error setting amount: %v\n", err) return } // Set currency code (ISO 4217) err = payment.SetCurrency("CZK") if err != nil { fmt.Printf("Error setting currency: %v\n", err) return } // Alternative: integer amounts payment2 := qrpay.NewEpcPayment() payment2.SetIBAN("DE89370400440532013000") payment2.SetRecipientName("Test Recipient") payment2.SetAmount("500") // 500.00 payment2.SetCurrency("EUR") // Generate strings to verify str1, _ := payment.GenerateString() str2, _ := payment2.GenerateString() fmt.Println("SPAYD with decimal amount:") fmt.Println(str1) fmt.Println("\nEPC with integer amount:") fmt.Println(str2) } ``` -------------------------------- ### Configure Payment Messages and References for EPC and SPAYD in Go Source: https://context7.com/dundee/qrpay/llms.txt Shows how to set payment messages, sender references, and recipient details for both EPC and SPAYD payment types using the qrpay library. This includes generating the payment strings and saving them as QR code images. ```go package main import ( "fmt" "github.com/dundee/qrpay" ) func main() { // EPC payment with full details epcPayment := qrpay.NewEpcPayment() epcPayment.SetIBAN("DE89370400440532013000") epcPayment.SetBIC("COBADEFFXXX") epcPayment.SetRecipientName("Online Shop GmbH") epcPayment.SetAmount("79.99") epcPayment.SetCurrency("EUR") // Set sender reference (remittance information) epcPayment.SetSenderReference("ORDER-2021-12-15-0042") // Set payment message/description epcPayment.SetMessage("Order #0042 - Electronics") // Set payment purpose code epcPayment.SetPurpose("GDDS") // Goods str, err := epcPayment.GenerateString() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Println("EPC Payment:") fmt.Println(str) // SPAYD payment with message spaydPayment := qrpay.NewSpaydPayment() spaydPayment.SetIBAN("CZ5855000000001265098001") spaydPayment.SetRecipientName("Jan Novak") spaydPayment.SetAmount("250.00") spaydPayment.SetCurrency("CZK") spaydPayment.SetSenderReference("REF2021123456") spaydPayment.SetMessage("Monthly subscription payment") str2, err := spaydPayment.GenerateString() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Println("\nSPAYD Payment:") fmt.Println(str2) // Generate QR codes qrpay.SaveQRCodeImageToFile(epcPayment, "epc-detailed.png") qrpay.SaveQRCodeImageToFile(spaydPayment, "spayd-detailed.png") fmt.Println("\nBoth QR codes generated successfully") } ``` -------------------------------- ### Go: Validate Payment Details and Generate QR Code Source: https://context7.com/dundee/qrpay/llms.txt This Go function demonstrates comprehensive validation for payment details (IBAN, BIC, amount, recipient) before generating an EPC payment string and saving a QR code image. It leverages the 'qrpay' library for setting and validating fields, checking for accumulated errors, and generating the final QR code. Dependencies include the 'fmt' package and the 'github.com/dundee/qrpay' library. Inputs are IBAN, BIC, amount, and recipient strings. Outputs include a success message and a PNG file, or an error if validation or generation fails. ```go package main import ( "fmt" "github.com/dundee/qrpay" ) func createPaymentWithValidation(iban, bic, amount, recipient string) error { payment := qrpay.NewEpcPayment() // Set and validate IBAN if err := payment.SetIBAN(iban); err != nil { return fmt.Errorf("IBAN validation failed for '%s': %v", iban, err) } // Set and validate BIC (optional but validated if provided) if bic != "" { if err := payment.SetBIC(bic); err != nil { return fmt.Errorf("BIC validation failed for '%s': %v", bic, err) } } // Set amount if err := payment.SetAmount(amount); err != nil { return fmt.Errorf("amount error: %v", err) } // Set recipient (mandatory for EPC) if recipient == "" { return fmt.Errorf("recipient name is mandatory for EPC payments") } if err := payment.SetRecipientName(recipient); err != nil { return fmt.Errorf("recipient error: %v", err) } // Check accumulated errors errors := payment.GetErrors() if len(errors) > 0 { fmt.Println("Validation errors detected:") for field, err := range errors { fmt.Printf(" - %s: %v\n", field, err) } return fmt.Errorf("payment has %d validation errors", len(errors)) } // Try to generate string (final validation) paymentString, err := payment.GenerateString() if err != nil { return fmt.Errorf("cannot generate payment string: %v", err) } fmt.Println("Payment string generated successfully:") fmt.Println(paymentString) // Try to generate QR code err = qrpay.SaveQRCodeImageToFile(payment, "validated-payment.png") if err != nil { return fmt.Errorf("QR code generation failed: %v", err) } fmt.Println("QR code saved successfully") return nil } func main() { // Test with valid data fmt.Println("=== Test 1: Valid Payment ===") err := createPaymentWithValidation( "DE89370400440532013000", "COBADEFFXXX", "100.00", "Test Company", ) if err != nil { fmt.Printf("Error: %v\n\n", err) } // Test with invalid IBAN fmt.Println("=== Test 2: Invalid IBAN ===") err = createPaymentWithValidation( "INVALID", "COBADEFFXXX", "100.00", "Test Company", ) if err != nil { fmt.Printf("Error: %v\n\n", err) } // Test with invalid BIC fmt.Println("=== Test 3: Invalid BIC ===") err = createPaymentWithValidation( "DE89370400440532013000", "INVALID", "100.00", "Test Company", ) if err != nil { fmt.Printf("Error: %v\n\n", err) } // Test with missing recipient fmt.Println("=== Test 4: Missing Recipient ===") err = createPaymentWithValidation( "DE89370400440532013000", "COBADEFFXXX", "100.00", "", ) if err != nil { fmt.Printf("Error: %v\n\n", err) } } ``` -------------------------------- ### Generate QR Code Image for Short Payment Descriptor (Go) Source: https://github.com/dundee/qrpay/blob/master/README.md Generates a QR code image file for a payment using the Short Payment Descriptor format. Requires setting various payment details like IBAN, amount, date, message, recipient name, notification type, notification value, and extended attributes. It saves the generated QR code to a specified file path. ```Go import "github.com/dundee/qrpay" import "time" p := qrpay.NewSpaydPayment() p.SetIBAN("CZ5855000000001265098001") p.SetAmount("10.8") p.SetDate(time.Date(2021, 12, 24, 0, 0, 0, 0, time.UTC)) p.SetMessage("M") p.SetRecipientName("go") p.SetNofificationType('E') p.SetNotificationValue("daniel@milde.cz") p.SetExtendedAttribute("vs", "1234567890") qrpay.SaveQRCodeImageToFile(p, "qr-payment.png") ``` -------------------------------- ### Validate IBAN and BIC with qrpaysdk (Go) Source: https://context7.com/dundee/qrpay/llms.txt Demonstrates how to set and validate International Bank Account Numbers (IBAN) and Bank Identifier Codes (BIC/SWIFT) using the qrpaysdk in Go. It shows successful validation, error handling for invalid inputs, and retrieving validation errors. Requires 'github.com/dundee/qrpay'. ```go package main import ( "fmt" "github.com/dundee/qrpay" ) func main() { payment := qrpay.NewSpaydPayment() // Valid IBAN - will succeed err := payment.SetIBAN("CZ5855000000001265098001") if err != nil { fmt.Printf("IBAN validation failed: %v\n", err) } else { fmt.Println("IBAN is valid") } // Valid BIC/SWIFT code err = payment.SetBIC("GIBACZPX") if err != nil { fmt.Printf("BIC validation failed: %v\n", err) } else { fmt.Println("BIC is valid") } // Invalid IBAN - will fail validation payment2 := qrpay.NewEpcPayment() err = payment2.SetIBAN("INVALID1234567890") if err != nil { fmt.Printf("Invalid IBAN detected: %v\n", err) } // Check all validation errors errors := payment2.GetErrors() if len(errors) > 0 { fmt.Println("\nValidation errors found:") for field, validationErr := range errors { fmt.Printf(" Field '%s': %v\n", field, validationErr) } } // Even with validation errors, other fields can be set payment2.SetRecipientName("Fallback Recipient") payment2.SetAmount("10.00") // GenerateString will return error if mandatory fields are invalid _, err = payment2.GenerateString() if err != nil { fmt.Printf("\nCannot generate payment string: %v\n", err) } } ``` -------------------------------- ### Generate SPAYD and EPC Payment Strings (Go) Source: https://context7.com/dundee/qrpay/llms.txt Generates raw payment strings for SPAYD and EPC formats without creating QR code images. This is useful for debugging or custom QR code generation. It requires the 'github.com/dundee/qrpay' package. ```go package main import ( "fmt" "github.com/dundee/qrpay" ) func main() { // SPAYD format string spaydPayment := qrpay.NewSpaydPayment() spaydPayment.SetIBAN("CZ5855000000001265098001") spaydPayment.SetAmount("108") spaydPayment.SetCurrency("CZK") spaydString, err := spaydPayment.GenerateString() if err != nil { fmt.Printf("Error generating SPAYD string: %v\n", err) return } fmt.Println("SPAYD Payment String:") fmt.Println(spaydString) // Output: SPD*1.0*ACC:CZ5855000000001265098001*AM:108*CC:CZK* // EPC format string epcPayment := qrpay.NewEpcPayment() epcPayment.SetIBAN("DE89370400440532013000") epcPayment.SetRecipientName("Test Company") epcPayment.SetAmount("99.99") epcPayment.SetCurrency("EUR") epcString, err := epcPayment.GenerateString() if err != nil { fmt.Printf("Error generating EPC string: %v\n", err) return } fmt.Println("\nEPC Payment String:") fmt.Println(epcString) // Output format: // BCD // 002 // 1 // SCT // // Test Company // DE89370400440532013000 // EUR99.99 } ``` -------------------------------- ### Generate QR Code Image for EPC QR Code (Go) Source: https://github.com/dundee/qrpay/blob/master/README.md Generates a QR code image file for a payment using the EPC QR Code format. Requires setting essential payment details such as IBAN, amount, message, and recipient name. The generated QR code is saved to a specified file path. ```Go import "github.com/dundee/qrpay" p := qrpay.NewEpcPayment() p.SetIBAN("CZ5855000000001265098001") p.SetAmount("10.8") p.SetMessage("M") p.SetRecipientName("go") qrpay.SaveQRCodeImageToFile(p, "qr-payment.png") ``` -------------------------------- ### Generate SPAYD Payment QR Code in Go Source: https://context7.com/dundee/qrpay/llms.txt Generates a QR code image in the Short Payment Descriptor (SPAYD) format for payments. This function supports setting various payment details like IBAN, amount, date, message, and extended attributes. The generated QR code can be saved as a PNG file or returned as a byte array. It requires the 'github.com/dundee/qrpay' package. ```go package main import ( "fmt" "time" "github.com/dundee/qrpay" ) func main() { // Create a new SPAYD payment object p := qrpay.NewSpaydPayment() // Set payment details err := p.SetIBAN("CZ5855000000001265098001") if err != nil { fmt.Printf("Invalid IBAN: %v\n", err) return } p.SetAmount("10.8") p.SetCurrency("CZK") p.SetDate(time.Date(2021, 12, 24, 0, 0, 0, 0, time.UTC)) p.SetMessage("Payment for invoice #123") p.SetRecipientName("John Doe") p.SetNofificationType('E') // E for email, P for phone p.SetNotificationValue("john@example.com") p.SetExtendedAttribute("vs", "1234567890") // Variable symbol p.SetExtendedAttribute("ks", "0308") // Constant symbol // Save QR code as image file err = qrpay.SaveQRCodeImageToFile(p, "payment-spayd.png") if err != nil { fmt.Printf("Failed to generate QR code: %v\n", err) return } fmt.Println("SPAYD QR code generated successfully") // Or get the QR code as byte array imageBytes, err := qrpay.GetQRCodeImage(p) if err != nil { fmt.Printf("Failed to generate QR code bytes: %v\n", err) return } fmt.Printf("Generated QR code size: %d bytes\n", len(imageBytes)) } ``` -------------------------------- ### Generate QR Code as Byte Array in Go Source: https://context7.com/dundee/qrpay/llms.txt This Go code snippet demonstrates how to retrieve a generated QR code as a byte array using the `qrpay` library. This byte array can be used for various purposes, including serving it as an HTTP response or storing it in a database. It handles setting payment details and error checking. ```go package main import ( "fmt" "io/ioutil" "net/http" "github.com/dundee/qrpay" ) func generatePaymentQR(w http.ResponseWriter, r *http.Request) { // Parse query parameters iban := r.URL.Query().Get("iban") amount := r.URL.Query().Get("amount") recipient := r.URL.Query().Get("recipient") // Create payment payment := qrpay.NewEpcPayment() err := payment.SetIBAN(iban) if err != nil { http.Error(w, "Invalid IBAN", http.StatusBadRequest) return } payment.SetRecipientName(recipient) payment.SetAmount(amount) payment.SetCurrency("EUR") // Get QR code as byte array qrCodeBytes, err := qrpay.GetQRCodeImage(payment) if err != nil { http.Error(w, fmt.Sprintf("Failed to generate QR code: %v", err), http.StatusInternalServerError) return } // Serve as PNG image w.Header().Set("Content-Type", "image/png") w.Header().Set("Content-Length", fmt.Sprintf("%d", len(qrCodeBytes))) w.Write(qrCodeBytes) } func saveQRToDatabase(payment qrpay.Payment) error { // Get QR code bytes qrBytes, err := qrpay.GetQRCodeImage(payment) if err != nil { return fmt.Errorf("failed to generate QR code: %v", err) } // Example: Save to file (in practice, save to database) err = ioutil.WriteFile("database/payment-qr.png", qrBytes, 0644) if err != nil { return fmt.Errorf("failed to save QR code: %v", err) } fmt.Printf("QR code saved: %d bytes\n", len(qrBytes)) return nil } func main() { // Example 1: HTTP endpoint http.HandleFunc("/generate-qr", generatePaymentQR) // Example 2: Save to database payment := qrpay.NewSpaydPayment() payment.SetIBAN("CZ5855000000001265098001") payment.SetRecipientName("Test Merchant") payment.SetAmount("100.00") err := saveQRToDatabase(payment) if err != nil { fmt.Printf("Error: %v\n", err) } fmt.Println("Starting HTTP server on :8080") fmt.Println("Example: http://localhost:8080/generate-qr?iban=DE89370400440532013000&amount=50.00&recipient=TestShop") // http.ListenAndServe(":8080", nil) } ``` -------------------------------- ### Generate EPC/SEPA Payment QR Code in Go Source: https://context7.com/dundee/qrpay/llms.txt Generates a QR code image using the European Payments Council (EPC) format for SEPA payments. This function allows setting mandatory fields like IBAN and recipient name, as well as optional fields such as BIC, amount, currency, reference, and message. It also includes a validation check for errors. The generated QR code is saved to a PNG file. Requires the 'github.com/dundee/qrpay' package. ```go package main import ( "fmt" "github.com/dundee/qrpay" ) func main() { // Create a new EPC payment object p := qrpay.NewEpcPayment() // Set mandatory fields err := p.SetIBAN("DE89370400440532013000") if err != nil { fmt.Printf("Invalid IBAN: %v\n", err) return } err = p.SetRecipientName("Mueller GmbH") if err != nil { fmt.Printf("Error setting recipient: %v\n", err) return } // Set optional fields p.SetBIC("COBADEFFXXX") p.SetAmount("150.50") p.SetCurrency("EUR") p.SetSenderReference("INV-2021-12-001") p.SetMessage("Invoice payment December") p.SetPurpose("GDDS") // Purpose code (e.g., GDDS for goods) // Generate and save QR code err = qrpay.SaveQRCodeImageToFile(p, "payment-epc.png") if err != nil { fmt.Printf("Failed to generate QR code: %v\n", err) return } fmt.Println("EPC QR code generated successfully") // Check for validation errors errors := p.GetErrors() if len(errors) > 0 { fmt.Println("Validation errors:") for field, err := range errors { fmt.Printf(" %s: %v\n", field, err) } } } ``` -------------------------------- ### Add Extended Attributes to SPAYD Payments in Go Source: https://context7.com/dundee/qrpay/llms.txt Demonstrates how to add custom extended attributes, including standard banking symbols (vs, ss, ks) and custom fields (invoiceId, customerId), to a SPAYD payment using the qrpay library. It generates the payment string and saves it as a QR code image. ```go package main import ( "fmt" "time" "github.com/dundee/qrpay" ) func main() { payment := qrpay.NewSpaydPayment() payment.SetIBAN("CZ5855000000001265098001") payment.SetAmount("500.00") payment.SetRecipientName("Company Ltd") payment.SetMessage("Invoice payment") // Add Czech banking symbols (common in CZ/SK payments) payment.SetExtendedAttribute("vs", "1234567890") // Variable symbol payment.SetExtendedAttribute("ss", "9876543210") // Specific symbol payment.SetExtendedAttribute("ks", "0308") // Constant symbol // Add custom extended attributes payment.SetExtendedAttribute("invoiceId", "INV-2021-1234") payment.SetExtendedAttribute("customerId", "CUST-5678") // Set payment date payment.SetDate(time.Date(2021, 12, 31, 0, 0, 0, 0, time.UTC)) // Set payment type payment.SetPaymentType("P2P") // Set notification preferences payment.SetNofificationType('E') // Email notification payment.SetNotificationValue("billing@company.com") // Generate payment string with all extended attributes paymentString, err := payment.GenerateString() if err != nil { fmt.Printf("Error: %v\n", err) return } fmt.Println("SPAYD Payment String with Extended Attributes:") fmt.Println(paymentString) // Save as QR code err = qrpay.SaveQRCodeImageToFile(payment, "payment-extended.png") if err != nil { fmt.Printf("QR code generation failed: %v\n", err) return } fmt.Println("\nQR code saved successfully with all extended attributes") } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.