From 838523995466dac2ba1ca199cbacda8a25b150b9 Mon Sep 17 00:00:00 2001 From: "rebeka.burnett" Date: Fri, 22 Dec 2023 16:58:46 +0100 Subject: [PATCH 1/4] Add a combined example --- code_samples/checkout_and_epayment.cs | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 code_samples/checkout_and_epayment.cs diff --git a/code_samples/checkout_and_epayment.cs b/code_samples/checkout_and_epayment.cs new file mode 100644 index 0000000..c257829 --- /dev/null +++ b/code_samples/checkout_and_epayment.cs @@ -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", + 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/acme-shop-123-order123abc", + }, + 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 socls", + ReturnUrl = "https://example.com/fallback-result-page-for-both-success-and-failure/acme-shop-123-order123abc", + Customer = new Epayment.Customer { PhoneNumber = CustomerPhoneNumber } +}; + +var epaymentResult = await vippsApi.EpaymentService.CreatePayment(epaymentRequest); + +Console.WriteLine("Open this link and approve the payment:" + epaymentResult.RedirectUrl); + + + From 9fc2bacbbd836c7a587ce1fb61ceb4ccf13b7bc6 Mon Sep 17 00:00:00 2001 From: "rebeka.burnett" Date: Fri, 22 Dec 2023 17:03:05 +0100 Subject: [PATCH 2/4] Fix bug --- code_samples/checkout_and_epayment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_samples/checkout_and_epayment.cs b/code_samples/checkout_and_epayment.cs index c257829..072051c 100644 --- a/code_samples/checkout_and_epayment.cs +++ b/code_samples/checkout_and_epayment.cs @@ -40,7 +40,7 @@ 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("PollingUrl:" + checkoutResult.PollingUrl); Console.WriteLine("CheckoutFrontendUrl:" + checkoutResult.CheckoutFrontendUrl); From 00f95c2994312799df9c9596becfc4876cdaedcf Mon Sep 17 00:00:00 2001 From: Rebeka Burnett <104833234+rebekaburnett@users.noreply.github.com> Date: Fri, 22 Dec 2023 17:10:12 +0100 Subject: [PATCH 3/4] Update checkout_and_epayment.cs --- code_samples/checkout_and_epayment.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code_samples/checkout_and_epayment.cs b/code_samples/checkout_and_epayment.cs index 072051c..7a48733 100644 --- a/code_samples/checkout_and_epayment.cs +++ b/code_samples/checkout_and_epayment.cs @@ -25,7 +25,7 @@ { CallbackAuthorizationToken = Guid.NewGuid().ToString(), CallbackUrl = "https://example.com/callbacks-for-checkout", - ReturnUrl = "https://example.com/fallback-result-page-for-both-success-and-failure/acme-shop-123-order123abc", + ReturnUrl = "https://example.com/fallback-result-page-for-both-success-and-failure", }, Transaction = new Checkout.PaymentTransaction { @@ -56,8 +56,8 @@ PaymentMethod = new Epayment.PaymentMethod { Type = Epayment.PaymentMethodType.WALLET }, UserFlow = Epayment.CreatePaymentRequestUserFlow.WEB_REDIRECT, Reference = ePaymentReference, - PaymentDescription = "Pair of socls", - ReturnUrl = "https://example.com/fallback-result-page-for-both-success-and-failure/acme-shop-123-order123abc", + PaymentDescription = "Pair of socks", + ReturnUrl = "https://example.com/fallback-result-page-for-both-success-and-failure", Customer = new Epayment.Customer { PhoneNumber = CustomerPhoneNumber } }; From fd9c8bf908b24abccc588b27ed5e61e062e7f0f3 Mon Sep 17 00:00:00 2001 From: Rebeka Burnett <104833234+rebekaburnett@users.noreply.github.com> Date: Tue, 2 Jan 2024 08:14:36 +0100 Subject: [PATCH 4/4] Update code_samples/checkout_and_epayment.cs OOps! Co-authored-by: Christian --- code_samples/checkout_and_epayment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_samples/checkout_and_epayment.cs b/code_samples/checkout_and_epayment.cs index 7a48733..0ad4015 100644 --- a/code_samples/checkout_and_epayment.cs +++ b/code_samples/checkout_and_epayment.cs @@ -11,7 +11,7 @@ ClientId = "YOUR-CLIENT-ID", ClientSecret = "YOUR-SECRET", MerchantSerialNumber = "YOUR-MSN", - SubscriptionKey = "YOUR-SUBSCRIPTION", + SubscriptionKey = "YOUR-SUBSCRIPTION-KEY", PluginName = "acme-plugin", PluginVersion = "1.0", UseTestMode = true