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

Switch to openapi-generator #68

Merged
merged 8 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
id-token: write
strategy:
matrix:
dotnet-version: [ '7.0.x' ]
dotnet-version: [ '8.0.x' ]
steps:
- name: Get repo
uses: actions/checkout@v3
Expand All @@ -43,7 +43,7 @@ jobs:
dotnet tool restore --tool-manifest src/.config/dotnet-tools.json
cd src
dotnet csharpier . --check
# - name: Install dependencies for IntegrationTests
# run: dotnet restore src/Tests/Vipps.net.IntegrationTests/Vipps.net.IntegrationTests.csproj
# - name: Run Integration Tests
# run: dotnet test src/Tests/Vipps.net.IntegrationTests/Vipps.net.IntegrationTests.csproj --no-restore --verbosity normal --environment vmp_net_sdk_CLIENT_ID=${{ secrets.CLIENT_ID }} --environment vmp_net_sdk_CLIENT_SECRET=${{ secrets.CLIENT_SECRET }} --environment vmp_net_sdk_SUBSCRIPTION_KEY=${{ secrets.SUBSCRIPTION_KEY }} --environment vmp_net_sdk_MERCHANT_SERIAL_NUMBER=${{ secrets.MERCHANT_SERIAL_NUMBER }}
- name: Install dependencies for IntegrationTests
run: dotnet restore src/Tests/Vipps.net.IntegrationTests/Vipps.net.IntegrationTests.csproj
- name: Run Integration Tests
run: dotnet test src/Tests/Vipps.net.IntegrationTests/Vipps.net.IntegrationTests.csproj --no-restore --verbosity normal --environment vmp_net_sdk_CLIENT_ID=${{ secrets.CLIENT_ID }} --environment vmp_net_sdk_CLIENT_SECRET=${{ secrets.CLIENT_SECRET }} --environment vmp_net_sdk_SUBSCRIPTION_KEY=${{ secrets.SUBSCRIPTION_KEY }} --environment vmp_net_sdk_MERCHANT_SERIAL_NUMBER=${{ secrets.MERCHANT_SERIAL_NUMBER }}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mono_crash.*
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
Expand Down Expand Up @@ -61,6 +62,9 @@ project.lock.json
project.fragment.lock.json
artifacts/

# ASP.NET Scaffolding
ScaffoldingReadMe.txt

# StyleCop
StyleCopReport.xml

Expand Down Expand Up @@ -137,6 +141,11 @@ _TeamCity*
.axoCover/*
!.axoCover/settings.json

# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info

# Visual Studio code coverage results
*.coverage
*.coveragexml
Expand Down Expand Up @@ -355,3 +364,6 @@ MigrationBackup/
# Do not include secrets from windows forms demo
/src/Vipps.net.WindowsFormsDemo/secrets.xml
/src/Vipps.net.AspDemo/secrets.xml

# Fody - auto-generated XML schema
FodyWeavers.xsd
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ℹ️ Documentation is available at:
[Vipps MobilePay SDK Documentation](https://developer.vippsmobilepay.com/docs/SDKs/).
[Vipps MobilePay SDK Documentation](https://developer.vippsmobilepay.com/docs/SDKs/).
37 changes: 37 additions & 0 deletions openapitools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"$schema": "https://raw.githubusercontent.com/OpenAPITools/openapi-generator-cli/master/apps/generator-cli/src/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "7.9.0",
"generators": {
"vipps-checkout": {
"generatorName": "csharp",
"output": ".",
"inputSpec": "https://developer.vippsmobilepay.com/redocusaurus/checkout-swagger-id.yaml",
"additionalProperties": {
"packageName": "Vipps.net.Models.Checkout",
"isLibrary": "false",
"targetFramework": "netstandard2.0",
"useNewtonsoft": "false",
"generateApiTests": "false",
"generateApiDocs": "false",
"generateModelDocs": "false"
}
},
"vipps-epayment": {
"generatorName": "csharp",
"output": ".",
"inputSpec": "https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml",
"additionalProperties": {
"packageName": "Vipps.net.Models.Epayment",
"isLibrary": "false",
"targetFramework": "netstandard2.0",
"useNewtonsoft": "false",
"generateApiTests": "false",
"generateApiDocs": "false",
"generateModelDocs": "false"
}
}
}
}
}
4 changes: 4 additions & 0 deletions src/.csharpierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Vipps.net.Models.Checkout/
Vipps.net.Models.Checkout.Test/
Vipps.net.Models.Epayment/
Vipps.net.Models.Epayment.Test/
6 changes: 6 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ dotnet_diagnostic.CS8618.severity = silent
# Core EditorConfig Options #
###############################

[Vipps.net.Models.Epayment/**/*.{cs,csproj}]
generated_code = true

[Vipps.net.Models.Checkout/**/*.{cs,csproj}]
generated_code = true

# All files
[*]
indent_style = space
Expand Down
38 changes: 20 additions & 18 deletions src/Tests/Vipps.net.IntegrationTests/CheckoutServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Vipps.net.IntegrationTests
using Vipps.net.Models.Checkout.Model;

namespace Vipps.net.IntegrationTests
{
[TestClass]
public class CheckoutServiceTests
Expand All @@ -8,30 +10,30 @@ public async Task Can_Create_And_Get_Session()
{
var vippsApi = TestSetup.CreateVippsAPI();
var reference = Guid.NewGuid().ToString();
var sessionInitiationRequest = new Models.Checkout.InitiateSessionRequest
{
Transaction = new Models.Checkout.PaymentTransaction
{
Amount = new Models.Checkout.Amount { Currency = "NOK", Value = 1000 },
Reference = reference,
PaymentDescription = nameof(CheckoutServiceTests.Can_Create_And_Get_Session),
},
MerchantInfo = new Models.Checkout.PaymentMerchantInfo
{
CallbackAuthorizationToken = Guid.NewGuid().ToString(),
CallbackUrl = "https://no.where.com/callback",
ReturnUrl = "https://no.where.com/return",
TermsAndConditionsUrl = "https://no.where.com/terms"
}
};
var sessionInitiationRequest = new InitiatePaymentSessionRequest(
new PaymentTransaction(
new Amount(1000, "NOK"),
reference,
nameof(Can_Create_And_Get_Session)
),
null,
"PAYMENT",
null,
new MerchantInfo(
"https://apitest.vipps.no/does-not-exist-callback",
"https://apitest.vipps.no/does-not-exist-return",
Guid.NewGuid().ToString(),
"https://apitest.vipps.no/does-not-exist-terms"
)
);

var sessionResponse = await vippsApi.CheckoutService.InitiateSession(
sessionInitiationRequest
);
Assert.IsNotNull(sessionResponse);
var sessionPolledResponse = await vippsApi.CheckoutService.GetSessionInfo(reference);
Assert.AreEqual(
Models.Checkout.ExternalSessionState.SessionCreated,
ExternalSessionState.SessionCreated,
sessionPolledResponse.SessionState
);
}
Expand Down
38 changes: 24 additions & 14 deletions src/Tests/Vipps.net.IntegrationTests/EpaymentServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Vipps.net.Models.Epayment;
using Vipps.net.Models.Epayment.Model;

namespace Vipps.net.IntegrationTests
{
Expand Down Expand Up @@ -45,20 +45,25 @@ public async Task Can_Create_Approve_Capture_Refund_Payment()

await vippsApi.EpaymentService.ForceApprovePayment(
reference,
new ForceApprove { Customer = new Customer { PhoneNumber = CustomerPhoneNumber } }
new ForceApprove
{
Customer = new Customer(
new CustomerPhoneNumber { PhoneNumber = CustomerPhoneNumber }
)
}
);

var captureResponse = await vippsApi.EpaymentService.CapturePayment(
reference,
new CaptureModificationRequest { ModificationAmount = createPaymentRequest.Amount }
new CaptureModificationRequest(createPaymentRequest.Amount)
);
Assert.IsNotNull(captureResponse);
Assert.AreEqual(reference, captureResponse.Reference);
Assert.AreEqual(State.AUTHORIZED, captureResponse.State);

var refundResponse = await vippsApi.EpaymentService.RefundPayment(
reference,
new RefundModificationRequest { ModificationAmount = createPaymentRequest.Amount }
new RefundModificationRequest(createPaymentRequest.Amount)
);
Assert.IsNotNull(refundResponse);
Assert.AreEqual(reference, refundResponse.Reference);
Expand All @@ -82,20 +87,25 @@ PaymentEventName paymentEventName

private static CreatePaymentRequest GetCreatePaymentRequest(string reference)
{
return new CreatePaymentRequest
{
Amount = new Amount
return new CreatePaymentRequest(
new Amount
{
Currency = Currency.NOK,
Value = 100 // 100 øre = 1 KR
},
PaymentMethod = new PaymentMethod { Type = PaymentMethodType.WALLET },
UserFlow = CreatePaymentRequestUserFlow.WEB_REDIRECT,
Reference = reference,
PaymentDescription = nameof(CheckoutServiceTests.Can_Create_And_Get_Session),
ReturnUrl = $"https://no.where.com/{reference}",
Customer = new Customer { }
};
new Customer(new CustomerPhoneNumber { PhoneNumber = CustomerPhoneNumber }),
null,
null,
null,
new PaymentMethod { Type = PaymentMethodType.WALLET },
null,
reference,
$"https://no.where.com/{reference}",
CreatePaymentRequest.UserFlowEnum.WEB_REDIRECT,
null,
null,
nameof(CheckoutServiceTests.Can_Create_And_Get_Session)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down Expand Up @@ -33,7 +33,7 @@
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Identity" Version="1.12.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
</ItemGroup>

Expand Down
8 changes: 4 additions & 4 deletions src/Vipps.net.AspCoreDemo/Controllers/CheckoutController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Vipps.net.Models.Checkout;
using Vipps.net.Models.Checkout.Model;
using Vipps.net.Services;

namespace Vipps.net.AspCore31Demo.Controllers
namespace Vipps.net.AspCoreDemo.Controllers
{
[ApiController]
[Route("[controller]")]
Expand All @@ -23,9 +23,9 @@ public CheckoutController(ILogger<CheckoutController> logger, IVippsApi vippsApi
[HttpPost]
public async Task<ActionResult<InitiateSessionResponse>> CreateSession()
{
var request = new InitiateSessionRequest
var request = new InitiatePaymentSessionRequest
{
MerchantInfo = new PaymentMerchantInfo
MerchantInfo = new MerchantInfo
{
CallbackAuthorizationToken = Guid.NewGuid().ToString(),
CallbackUrl = "https://your-url-here.com:3000",
Expand Down
12 changes: 7 additions & 5 deletions src/Vipps.net.AspCoreDemo/Controllers/EpaymentController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Vipps.net.Models.Epayment;
using Vipps.net.Models.Epayment.Model;
using Vipps.net.Services;
using Amount = Vipps.net.Models.Epayment.Model.Amount;
using PaymentMethod = Vipps.net.Models.Epayment.Model.PaymentMethod;

namespace Vipps.net.AspCore31Demo.Controllers
namespace Vipps.net.AspCoreDemo.Controllers
{
[ApiController]
[Route("[controller]")]
Expand All @@ -24,12 +26,12 @@ public async Task<string> CreatePayment()
{
Amount = new Amount { Value = 1000, Currency = Currency.NOK },
PaymentMethod = new PaymentMethod { Type = PaymentMethodType.WALLET },
Customer = new Customer { PhoneNumber = "4747375750" },
Customer = new Customer(new CustomerPhoneNumber { PhoneNumber = "4747375750" }),
Reference = Guid.NewGuid().ToString(),
UserFlow = CreatePaymentRequestUserFlow.WEB_REDIRECT,
UserFlow = CreatePaymentRequest.UserFlowEnum.WEB_REDIRECT,
ReturnUrl = $"http://localhost:3000",
PaymentDescription = "paymentDescription",
Profile = new ProfileRequest { Scope = "name phoneNumber address birthDate email" },
Profile = new ProfileRequest { Scope = "name phoneNumber address birthDate email" }
};

var result = await _epaymentService.CreatePayment(request);
Expand Down
1 change: 1 addition & 0 deletions src/Vipps.net.AspCoreDemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Vipps.net.AspCoreDemo;

namespace Vipps.net.AspCore31Demo
{
Expand Down
2 changes: 1 addition & 1 deletion src/Vipps.net.AspCoreDemo/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Microsoft.OpenApi.Models;
using Vipps.net.Infrastructure;

namespace Vipps.net.AspCore31Demo
namespace Vipps.net.AspCoreDemo
{
public class Startup
{
Expand Down
4 changes: 2 additions & 2 deletions src/Vipps.net.AspCoreDemo/Vipps.net.AspCoreDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<UserSecretsId>5fcb55b3-f577-4b73-a82a-f13b33796367</UserSecretsId>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Identity" Version="1.12.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
40 changes: 0 additions & 40 deletions src/Vipps.net.Codegen/CodegenSettings.cs

This file was deleted.

Loading
Loading