Skip to content

CyberSource ​

CyberSource Secure Acceptance is a hosted checkout for card payments, in MMK or any other currency.

CallWhat it doesReturns
cs.Initiate(data)Signed form posted to the hosted checkout*FormPayment
cs.HandleCallback(request)Verify the result post*PaymentCallback

CyberSource has no status API in this package: the callback is the only payment result.

Responses shows what CyberSource puts in each result.

How it works ​

CyberSource posts the result twice, to your backoffice URL and through the browser to your receipt page, and both are verified the same way.

CyberSource: signed form, hosted checkout, two result postsCustomerYour appCyberSourceCheck outSigned form, auto-submitscs.Initiate(data)Post to the hosted checkoutPOST /pay, then the card formBackoffice postoverride_backoffice_post_urlVerified callback is proofcs.HandleCallback(request)Browser posts the receiptoverride_custom_receipt_pageSame signature checkcs.HandleCallback(request)Show the receipt
CyberSource: signed form, hosted checkout, two result posts

Initiating a Payment ​

go
import (
	"fmt"
	"io"

	myanmarpayments "github.com/laranex/go-myanmar-payments/v4"
	"github.com/laranex/go-myanmar-payments/v4/cybersource"
)

cs, err := cybersource.New(cybersource.Config{
	ProfileID: "...",
	AccessKey: "...",
	SecretKey: "...",
})
if err != nil {
	return err
}

data := cybersource.PaymentData{
	OrderID:         fmt.Sprintf("ORDER_%d", order.ID),
	Amount:          myanmarpayments.Kyat(10000),
	CallbackURL:     "https://shop.test/payments/cybersource/callback",
	Currency:        "MMK",
	TransactionType: cybersource.Sale,
	Locale:          "en-us",
	ReturnURL:       "https://shop.test/payments/cybersource/receipt",
	CancelURL:       "https://shop.test/checkout",
}

payment, err := cs.Initiate(data)
if err != nil {
	return err
}

// The page posts the signed form to CyberSource on load.
w.Header().Set("Content-Type", "text/html; charset=utf-8")
io.WriteString(w, payment.HTML())

cybersource.PaymentData ​

FieldTypeRequiredRules
OrderIDstringYesAt most 50 characters, sent as reference_number
Amountmyanmarpayments.AmountYesOrder total in Currency, 0 or more, any number of decimals, at most 15 characters, e.g. Kyat(10000) or MustParseAmount("10.50")
CallbackURLstringYesAbsolute http or https URL CyberSource posts the result to. At most 255 characters; CyberSource may require HTTPS in production
CurrencystringYesAny three-letter uppercase ISO 4217 code, e.g. MMK
TransactionTypecybersource.TransactionTypeYescybersource.Sale ("sale"), .Authorization ("authorization"), .SaleAndCreateToken ("sale,create_payment_token") or .AuthorizationAndCreateToken ("authorization,create_payment_token")
LocalestringYesHosted page language as a CyberSource locale code, e.g. en-us
ReturnURLstringNoReceipt page for the customer (absolute http or https URL). At most 255 characters
CancelURLstringNoPage shown when the customer cancels (absolute http or https URL). At most 255 characters

Amounts and Currencies ​

CyberSource is multi-currency and accepts decimals. For another currency, pass an Amount with the currency: Amount: myanmarpayments.MustParseAmount("10.50"), Currency: "USD".

Form Encoding ​

CyberSource expects the form as application/x-www-form-urlencoded. payment.Enctype carries it; use it if you render the form yourself.

Handling Callbacks ​

CyberSource posts a form to CallbackURL. The same check works for the browser post to your receipt page.

go
import (
	"net/http"

	myanmarpayments "github.com/laranex/go-myanmar-payments/v4"
)

// POST /payments/cybersource/callback
request, err := myanmarpayments.NewCallbackRequestFromHTTP(r)
if err != nil {
	http.Error(w, "invalid callback", http.StatusBadRequest)
	return
}
callback, err := cs.HandleCallback(request)
if err != nil {
	http.Error(w, "invalid callback", http.StatusBadRequest)
	return
}

if callback.IsSuccessful() {
	// callback.OrderID is your req_reference_number
	// callback.GatewayReference is CyberSource's transaction_id
}

callback.Acknowledgement.Write(w)

Only signed fields are trusted: decision and req_reference_number must be listed in signed_field_names, transaction_id and the amount are read only when they are signed, and Raw keeps only the signed fields plus signature. An unsigned extra field, such as decision=ACCEPT added to a re-posted checkout form, can't change the result.

Responses ​

What CyberSource puts in each field. See Results and PaymentCallback & Status for the full structs. On error the result is nil. A field the gateway didn't send is "". CyberSource posts form fields, so every Raw value is a string, exactly as sent.

Initiate() → *myanmarpayments.FormPayment ​

Field / MethodCyberSource value
Flow()FlowForm
OrderIDYour data.OrderID
Action{BaseURL}/pay, e.g. https://secureacceptance.cybersource.com/pay
FieldsThe signed fields below, in signing order. Post them unchanged
Enctypeapplication/x-www-form-urlencoded
HTML()A full HTML page that posts Fields to Action on load
Form fieldValue
access_keyConfig.AccessKey
profile_idConfig.ProfileID
transaction_uuidA random ID, new for every call
signed_field_namesThe field names in this table except signature, comma-separated
signed_date_timeUTC time, e.g. 2026-10-08T09:30:00Z
localedata.Locale
transaction_typedata.TransactionType
reference_numberdata.OrderID
amountdata.Amount, e.g. 10000
currencydata.Currency
override_custom_receipt_pagedata.ReturnURL, "" when unset
override_backoffice_post_urldata.CallbackURL
override_custom_cancel_pagedata.CancelURL, "" when unset
signatureBase64 HMAC-SHA256 of the signed fields

Initiate makes no HTTP call, so it takes no context and cybersource.New takes no HTTP client. FormPayment has no Raw: nothing is sent to CyberSource until the customer's browser posts the form.

HandleCallback() → *myanmarpayments.PaymentCallback ​

FieldCyberSource value
OrderIDCyberSource req_reference_number (your OrderID)
Statusdecision mapped, see Statuses
GatewayStatusCyberSource decision, trimmed and uppercased, e.g. ACCEPT
GatewayReferenceCyberSource transaction_id. "" when it is not signed
AmountCyberSource auth_amount, falling back to req_amount when it is missing or empty, e.g. 10000. Signed values only
RawThe signed fields of the verified post plus signature, e.g. decision, reason_code, message, transaction_id, auth_amount, auth_code, req_reference_number, req_amount, req_currency, req_transaction_uuid, signed_field_names, signed_date_time. Unsigned fields are left out
AcknowledgementHTTP 200, empty body, Content-Type: text/plain

Statuses ​

CyberSource decisionPaymentStatus
ACCEPTStatusSuccessful
REVIEWStatusPending
DECLINE, ERRORStatusFailed
CANCELStatusCanceled
anything elseStatusUnknown

Errors ​

CallReturnsWhen
Initiate()*InvalidPaymentDataErrordata.Validate() fails. Nothing is signed
HandleCallback()*SignatureVerificationErrorsignature doesn't match, a field listed in signed_field_names is missing or holds an object or array, or decision or req_reference_number isn't signed

The error types live in the root myanmarpayments package. CyberSource makes no HTTP calls, so nothing returns *APIError.

Released under the MIT License, except where a package says otherwise.