Detailed guide: https://doc.gopay.com
- .NET Standard 2.0
This library is avalaible from NuGet Package Manager
PM> Install-Package GOPAY.NET
- Newtonsoft.Json
- Restsharp
- Restsharp.Newtonsoft.Json
using GoPay.Common;
using GoPay.Model;
using GoPay.Payment;
var connector = new GPConnector(<API_URL>,<USER_ID>, <USER_SECRET>);
The connector provides methods for interacting with our gateway.
To be able to communicate with our gateway it's required to create an auth token.
var connector = new GPConnector(<API_URL>,<USER_ID>, <USER_SECRET>);
connector.GetAppToken();
The token gets cached in an instance of GPConnector and its lifetime is 30 minutes. The method GetAppToken()
creates token in a scope "payment-create"
. If you would like to create a token in a different scope call method GetAppToken(<SCOPE>)
Once the token expires its required to obtain a new one by calling the method getAppToken again.
var payment = new BasePayment()
{
Currency = <Currency>,
Lang = "ENG",
OrderNumber = "789456167879",
Amount = 7500,
Target = new Target()
{
GoId = <GOID>,
Type = Target.TargetType.ACCOUNT
},
Callback = new Callback()
{
NotificationUrl = <NOTIFICATION_URL>,
ReturnUrl = <RETURN_URL>
},
Payer = new Payer()
{
Contact = new PayerContact()
{
Email = "test@test.gopay.cz"
},
DefaultPaymentInstrument = PaymentInstrument.PAYMENT_CARD
}
};
try {
var result = connector.CreatePayment(payment);
} catch (GPClientException e) {
//
}
try {
var payment = connector.PaymentStatus(<PAYMENT_ID>);
} catch (GPClientException e) {
//
}
try {
var result = connector.RefundPayment(<PAYMENT_ID>, <AMOUNT>);
} catch (GPClientException e) {
//
}
var payment = new BasePayment()
{
PreAuthorize = true,
...
};
try {
connector.CreatePayment(payment);
} catch (GPClientException ex) {
//
}
try {
var result = connector.VoidAuthorization(<ID>);
} catch (GPClientException ex) {
//
}
var recurrence = new NextPayment()
{
Amount = <Amount>,
Currency = <Currency>,
OrderNumber = <OrderNumber>
};
try {
connector.CreateRecurrentPayment(payment);
} catch {GPClientException e) {
//
}
var recurrence = new Recurrence()
{
Cycle = RecurrenceCycle.DAY,
DateTo = new DateTime(2020, 12, 12),
Period = 5
};
var payment = new BasePayment();
payment.Recurrence = recurrence;
try {
connector.CreatePayment(payment);
} catch {GPClientException e) {
//
}
try {
var capture = connector.CapturePayment(<ID>);
} catch (GPClientException ex) {
//
}
try {
var voidRecurrency = connector.VoidRecurrency(<ID>);
} catch (GPClientException ex) {
//
}
All methods above throw checked exception GPClientException on a failure.
try {
connector.getAppToken().CreatePayment(payment);
} catch (GPClientException e) {
var err = exception.Error;
var date = err.DateIssued;
foreach (var element in err.ErrorMessages)
{
//
}
}
Contributions from others would be very much appreciated! Send pull request/ issue. Thanks!
Copyright (c) 2016 GoPay.com. MIT Licensed, see LICENSE for details.