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

Add a combined example #66

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions code_samples/checkout_and_epayment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

using Vipps.net;
using Vipps.net.Infrastructure;
using Checkout = Vipps.net.Models.Checkout;
using Epayment = Vipps.net.Models.Epayment;

const string CustomerPhoneNumber = "YOUR-TEST-PHONENUMBER";

var vippsConfigurationOptions = new VippsConfigurationOptions
{
ClientId = "YOUR-CLIENT-ID",
ClientSecret = "YOUR-SECRET",
MerchantSerialNumber = "YOUR-MSN",
SubscriptionKey = "YOUR-SUBSCRIPTION",
rebekaburnett marked this conversation as resolved.
Show resolved Hide resolved
PluginName = "acme-plugin",
PluginVersion = "1.0",
UseTestMode = true
};

var vippsApi = new VippsApi(vippsConfigurationOptions);

var checkoutRequest = new Checkout.InitiateSessionRequest
{
MerchantInfo = new Checkout.PaymentMerchantInfo
{
CallbackAuthorizationToken = Guid.NewGuid().ToString(),
CallbackUrl = "https://example.com/callbacks-for-checkout",
ReturnUrl = "https://example.com/fallback-result-page-for-both-success-and-failure",
},
Transaction = new Checkout.PaymentTransaction
{
Amount = new Checkout.Amount { Currency = "NOK", Value = 10000 },
PaymentDescription = "Checkout description",
Reference = Guid.NewGuid().ToString()
}
};

var checkoutResult = await vippsApi.CheckoutService.InitiateSession(checkoutRequest);

Console.WriteLine("Here is the response from the checkout service:");
Console.WriteLine("Token:" + checkoutResult.Token);
Console.WriteLine("AdditionalProperties:" + checkoutResult.AdditionalProperties);
Console.WriteLine("PollingUrl:" + checkoutResult.PollingUrl);
Console.WriteLine("CheckoutFrontendUrl:" + checkoutResult.CheckoutFrontendUrl);


var ePaymentReference = Guid.NewGuid().ToString();

var epaymentRequest = new Epayment.CreatePaymentRequest
{
Amount = new Epayment.Amount
{
Currency = Epayment.Currency.NOK,
Value = 100 // 100 øre = 1 KR
},
PaymentMethod = new Epayment.PaymentMethod { Type = Epayment.PaymentMethodType.WALLET },
UserFlow = Epayment.CreatePaymentRequestUserFlow.WEB_REDIRECT,
Reference = ePaymentReference,
PaymentDescription = "Pair of socks",
ReturnUrl = "https://example.com/fallback-result-page-for-both-success-and-failure",
Customer = new Epayment.Customer { PhoneNumber = CustomerPhoneNumber }
};

var epaymentResult = await vippsApi.EpaymentService.CreatePayment(epaymentRequest);

Console.WriteLine("Open this link and approve the payment:" + epaymentResult.RedirectUrl);



Loading