Skip to content

Commit

Permalink
added Swish payin method
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Feb 10, 2025
1 parent 02fcf3d commit 38b846e
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 18 deletions.
29 changes: 29 additions & 0 deletions MangoPay.SDK.Tests/ApiPayInsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,35 @@ public async Task Test_PayIns_Create_GiropayWeb()
}
}

[Test]
public async Task Test_PayIns_Create_SwishWeb()
{
try
{
var user = await GetJohn();
var payIn = await GetNewPayInSwishWeb();
var fetched = await Api.PayIns.GetSwishAsync(payIn.Id);

Assert.IsTrue(payIn.Id.Length > 0);
Assert.AreEqual(PayInPaymentType.SWISH, payIn.PaymentType);
Assert.AreEqual(PayInExecutionType.WEB, payIn.ExecutionType);
Assert.IsTrue(payIn.DebitedFunds is Money);
Assert.IsTrue(payIn.CreditedFunds is Money);
Assert.IsTrue(payIn.Fees is Money);
Assert.AreEqual(user.Id, payIn.AuthorId);
Assert.AreEqual(TransactionStatus.CREATED, payIn.Status);
Assert.AreEqual(TransactionType.PAYIN, payIn.Type);
Assert.AreEqual(TransactionNature.REGULAR, payIn.Nature);

Assert.AreEqual(payIn.Id, fetched.Id);
Assert.IsNotNull(fetched.Id);
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
}

[Test]
public async Task Test_PayIns_Create_BancontactWeb()
{
Expand Down
43 changes: 35 additions & 8 deletions MangoPay.SDK.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
using Common.Logging.Simple;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using MangoPay.SDK.Core;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
Expand All @@ -7,12 +12,6 @@
using MangoPay.SDK.Entities.PUT;
using NUnit.Framework;
using RestSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

namespace MangoPay.SDK.Tests
{
Expand Down Expand Up @@ -215,7 +214,13 @@ protected async Task<WalletDTO> GetJohnsWallet()

return BaseTest._johnsWallet;
}


protected async Task<WalletDTO> GetNewWallet(CurrencyIso currencyIso)
{
var john = await this.GetJohn();
var wallet = new WalletPostDTO(new List<string> { john.Id }, $"Wallet in {currencyIso.ToString()}", currencyIso);
return await this.Api.Wallets.CreateAsync(wallet);
}

protected async Task<WalletDTO> CreateJohnsWallet()
{
Expand Down Expand Up @@ -453,6 +458,12 @@ protected async Task<PayInGiropayWebDTO> GetNewPayInGiropayWeb()
return await this.Api.PayIns.CreateGiropayWebAsync(payIn);
}

protected async Task<PayInSwishWebDTO> GetNewPayInSwishWeb()
{
PayInSwishWebPostDTO payIn = await GetPayInSwishWebPost();
return await this.Api.PayIns.CreateSwishWebAsync(payIn);
}

protected async Task<PayInBancontactWebDTO> GetNewPayInBancontactWeb()
{
PayInBancontactWebPostDTO payIn = await GetPayInBancontactWebPost();
Expand Down Expand Up @@ -806,6 +817,22 @@ protected async Task<PayInGiropayWebPostDTO> GetPayInGiropayWebPost()
return payIn;
}

protected async Task<PayInSwishWebPostDTO> GetPayInSwishWebPost()
{
var wallet = await GetNewWallet(CurrencyIso.SEK);
var user = await GetJohn();

var payIn = new PayInSwishWebPostDTO(
user.Id,
new Money { Amount = 100, Currency = CurrencyIso.SEK },
new Money { Amount = 0, Currency = CurrencyIso.SEK },
wallet.Id,
"http://www.my-site.com/returnURL?transactionId=wt_71a08458-b0cc-468d-98f7-1302591fc238"
);

return payIn;
}

protected async Task<PayInBancontactWebPostDTO> GetPayInBancontactWebPost()
{
var wallet = await GetJohnsWalletWithMoney();
Expand Down
9 changes: 5 additions & 4 deletions MangoPay.SDK/Core/APIs/ApiBase.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.GET;
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.GET;

namespace MangoPay.SDK.Core.APIs
{
Expand Down Expand Up @@ -74,6 +74,7 @@ public abstract class ApiBase
{ MethodKey.PayinsIdealWebCreate, new ApiEndPoint("/payins/payment-methods/ideal", RequestType.POST)},
{ MethodKey.PayinsGiropayWebCreate, new ApiEndPoint("/payins/payment-methods/giropay", RequestType.POST)},
{ MethodKey.PayinsBancontactWebCreate, new ApiEndPoint("/payins/payment-methods/bancontact", RequestType.POST)},
{ MethodKey.PayinsSwishWebCreate, new ApiEndPoint("/payins/payment-methods/swish", RequestType.POST)},

{ MethodKey.PayinsRecurringRegistration, new ApiEndPoint("/recurringpayinregistrations", RequestType.POST)},
{ MethodKey.PayinsGetRecurringRegistration, new ApiEndPoint("/recurringpayinregistrations/{0}", RequestType.GET)},
Expand Down
28 changes: 23 additions & 5 deletions MangoPay.SDK/Core/APIs/ApiPayIns.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities.GET;
using MangoPay.SDK.Entities.POST;
using System;
using System.Collections.Generic;
using System;
using System.Threading.Tasks;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.GET;
using MangoPay.SDK.Entities.POST;
using MangoPay.SDK.Entities.PUT;

namespace MangoPay.SDK.Core.APIs
Expand Down Expand Up @@ -175,6 +174,17 @@ public async Task<PayInGiropayWebDTO> CreateGiropayWebAsync(PayInGiropayWebPostD
MethodKey.PayinsGiropayWebCreate, payIn, idempotentKey);
}

/// <summary>Creates new payin Swish web.</summary>
/// <param name="idempotentKey">Idempotent key for this request.</param>
/// <param name="payIn">Object instance to be created.</param>
/// <returns>Object instance returned from API.</returns>
public async Task<PayInSwishWebDTO> CreateSwishWebAsync(PayInSwishWebPostDTO payIn,
string idempotentKey = null)
{
return await this.CreateObjectAsync<PayInSwishWebDTO, PayInSwishWebPostDTO>(
MethodKey.PayinsSwishWebCreate, payIn, idempotentKey);
}

/// <summary>Creates new payin bancontact web.</summary>
/// <param name="idempotentKey">Idempotent key for this request.</param>
/// <param name="payIn">Object instance to be created.</param>
Expand Down Expand Up @@ -337,6 +347,14 @@ public async Task<PayInGiropayWebDTO> GetGiropayAsync(string payInId)
return await this.GetObjectAsync<PayInGiropayWebDTO>(MethodKey.PayinsGet, entitiesId: payInId);
}

/// <summary>Gets PayIn Swish entity by its identifier.</summary>
/// <param name="payInId">PayIn identifier.</param>
/// <returns>PayIn object returned from API.</returns>
public async Task<PayInSwishWebDTO> GetSwishAsync(string payInId)
{
return await this.GetObjectAsync<PayInSwishWebDTO>(MethodKey.PayinsGet, entitiesId: payInId);
}

/// <summary>Gets PayIn Bancontact entity by its identifier.</summary>
/// <param name="payInId">PayIn identifier.</param>
/// <returns>PayIn object returned from API.</returns>
Expand Down
1 change: 1 addition & 0 deletions MangoPay.SDK/Core/Enumerations/MethodKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public enum MethodKey
PayinsSatispayWebCreate,
PayinsBlikWebCreate,
PayinsKlarnaWebCreate,
PayinsSwishWebCreate,
PayinsIdealWebCreate,
PayinsGiropayWebCreate,
PayinsBancontactWebCreate,
Expand Down
12 changes: 11 additions & 1 deletion MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,29 @@ public enum PayInPaymentType

/// <summary> Mbway payment type </summary>
MBWAY,

/// <summary> Multibanco payment type </summary>
MULTIBANCO,

/// <summary> Satispay payment type </summary>
SATISPAY,

/// <summary> Blik payment type </summary>
BLIK,

/// <summary> Klarna payment type </summary>
KLARNA,

/// <summary> Ideal payment type </summary>
IDEAL,

/// <summary> Giropay payment type </summary>
GIROPAY,

/// <summary> Bancontact payment type </summary>
BCMC
BCMC,

/// <summary> Swish payment type </summary>
SWISH
}
}
30 changes: 30 additions & 0 deletions MangoPay.SDK/Entities/GET/PayInSwishWebDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace MangoPay.SDK.Entities.GET
{
public class PayInSwishWebDTO: PayInDTO
{
/// <summary>An optional value to be specified on the user's bank statement.</summary>
public string StatementDescriptor { get; set; }

/// <summary> The URL to redirect to after the payment, whether the transaction was successful or not </summary>
public string ReturnURL { get; set; }

/// <summary> The URL to which the user is redirected to complete the payment </summary>
public string RedirectURL { get; set; }

/// <summary> The mobile URL to which to redirect the user to complete the payment in an app-to-app flow. </summary>
public string DeepLinkURL { get; set; }

/// <summary> The PNG file of the Swish QR code as a Base64-encoded string. </summary>
public string QRCodeURL { get; set; }

/// <summary>
/// <p>Allowed values: WEB, APP</p>
/// <p>Default value: WEB</p>
/// <p>The platform environment of the post-payment flow. The PaymentFlow value combines with the ReturnURL to manage the redirection behavior after payment:</p>
/// <p>Set the value to APP to send the user to your platform’s mobile app</p>
/// <p>Set the value to WEB to send the user to a web browser</p>
/// <p>In both cases you need to provide the relevant ReturnURL, whether to your app or website.</p>
/// </summary>
public string PaymentFlow { get; set; }
}
}
42 changes: 42 additions & 0 deletions MangoPay.SDK/Entities/POST/PayInSwishWebPostDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace MangoPay.SDK.Entities.GET
{
public class PayInSwishWebPostDTO: EntityPostBase
{
public PayInSwishWebPostDTO(string authorId, Money debitedFunds, Money fees, string creditedWalletId, string returnUrl)
{
AuthorId = authorId;
DebitedFunds = debitedFunds;
Fees = fees;
CreditedWalletId = creditedWalletId;
ReturnURL = returnUrl;
}

/// <summary>Author identifier.</summary>
public string AuthorId { get; set; }

/// <summary>Debited funds.</summary>
public Money DebitedFunds { get; set; }

/// <summary>Fees.</summary>
public Money Fees { get; set; }

/// <summary>Credited wallet identifier.</summary>
public string CreditedWalletId { get; set; }

/// <summary> The URL to redirect to after the payment, whether the transaction was successful or not
public string ReturnURL { get; set; }

/// <summary>An optional value to be specified on the user's bank statement.</summary>
public string StatementDescriptor { get; set; }

/// <summary>
/// <p>Allowed values: WEB, APP</p>
/// <p>Default value: WEB</p>
/// <p>The platform environment of the post-payment flow. The PaymentFlow value combines with the ReturnURL to manage the redirection behavior after payment:</p>
/// <p>Set the value to APP to send the user to your platform’s mobile app</p>
/// <p>Set the value to WEB to send the user to a web browser</p>
/// <p>In both cases you need to provide the relevant ReturnURL, whether to your app or website.</p>
/// </summary>
public string PaymentFlow { get; set; }
}
}

0 comments on commit 38b846e

Please sign in to comment.