Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"URL not set" in webhooks, how do I set callbackURL? #140

Open
febriliankr opened this issue Feb 5, 2024 · 0 comments
Open

"URL not set" in webhooks, how do I set callbackURL? #140

febriliankr opened this issue Feb 5, 2024 · 0 comments

Comments

@febriliankr
Copy link

I still got "URL not set" in webhooks section of Xendit dashboard.
image

Here's my code:

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"
	"os"

	"github.com/google/uuid"
	"github.com/joho/godotenv"
	xendit "github.com/xendit/xendit-go/v4"
	"github.com/xendit/xendit-go/v4/payment_request"
)

func main() {

	err := godotenv.Load()
	if err != nil {
		log.Fatal("Error loading .env file")
	}

	xenditApiKey := os.Getenv("XENDIT_API_KEY")
	xenditV4 := xendit.NewClient(xenditApiKey)

	/*
		QR Code creation V4
	*/
	callbackURL := "https://<API_ENDPOINT>/qris/callback"
	var amount float64 = 3000
	var orderID = "order-dijd0q8je0182ej"

	// idempotencyKey is important to prevent double request, enabling retry
	var idempotencyKey = fmt.Sprintf("qr-%s", uuid.New().String())
	channelProperties := payment_request.PaymentRequestParametersChannelProperties{
		SuccessReturnUrl: &callbackURL,
	}

	qrCode := payment_request.QRCodeParameters{
		ChannelCode: *payment_request.NewNullableQRCodeChannelCode(payment_request.QRCODECHANNELCODE_DANA.Ptr()),
	}

	paymentMethod := payment_request.PaymentMethodParameters{
		ReferenceId: &orderID,
		Type:        payment_request.PAYMENTMETHODTYPE_QR_CODE,
		Reusability: payment_request.PAYMENTMETHODREUSABILITY_ONE_TIME_USE,
		QrCode:      *payment_request.NewNullableQRCodeParameters(&qrCode),
	}

	paymentRequestParameters := payment_request.PaymentRequestParameters{
		Amount:            &amount,
		Currency:          "IDR",
		PaymentMethod:     &paymentMethod,
		ChannelProperties: &channelProperties,
	}

	createPRResp, _, createPRErr := xenditV4.PaymentRequestApi.
		CreatePaymentRequest(context.Background()).
		PaymentRequestParameters(paymentRequestParameters).
		IdempotencyKey(idempotencyKey).
		Execute()

	if createPRErr != nil {
		fmt.Fprintf(os.Stdout, "Create QR Payment Request Err`: %v\n", createPRErr)
	} else {
		fmt.Println(jsonStr(createPRResp))
		// qrString := createPRResp.PaymentMethod.QrCode.Get().ChannelProperties.QrString
		// expiresAt := createPRResp.PaymentMethod.QrCode.Get().ChannelProperties.QrString
	}

}

func jsonStr(data any) string {
	j, _ := json.Marshal(data)
	return string(j)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant