diff --git a/MangoPay.SDK.Tests/ApiPayInsTest.cs b/MangoPay.SDK.Tests/ApiPayInsTest.cs index 52ae640e..07b57b95 100644 --- a/MangoPay.SDK.Tests/ApiPayInsTest.cs +++ b/MangoPay.SDK.Tests/ApiPayInsTest.cs @@ -502,6 +502,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() { diff --git a/MangoPay.SDK.Tests/BaseTest.cs b/MangoPay.SDK.Tests/BaseTest.cs index 360646ea..d6679f15 100644 --- a/MangoPay.SDK.Tests/BaseTest.cs +++ b/MangoPay.SDK.Tests/BaseTest.cs @@ -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; @@ -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 { @@ -215,7 +214,13 @@ protected async Task GetJohnsWallet() return BaseTest._johnsWallet; } - + + protected async Task GetNewWallet(CurrencyIso currencyIso) + { + var john = await this.GetJohn(); + var wallet = new WalletPostDTO(new List { john.Id }, $"Wallet in {currencyIso.ToString()}", currencyIso); + return await this.Api.Wallets.CreateAsync(wallet); + } protected async Task CreateJohnsWallet() { @@ -453,6 +458,12 @@ protected async Task GetNewPayInGiropayWeb() return await this.Api.PayIns.CreateGiropayWebAsync(payIn); } + protected async Task GetNewPayInSwishWeb() + { + PayInSwishWebPostDTO payIn = await GetPayInSwishWebPost(); + return await this.Api.PayIns.CreateSwishWebAsync(payIn); + } + protected async Task GetNewPayInBancontactWeb() { PayInBancontactWebPostDTO payIn = await GetPayInBancontactWebPost(); @@ -806,6 +817,22 @@ protected async Task GetPayInGiropayWebPost() return payIn; } + protected async Task 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 GetPayInBancontactWebPost() { var wallet = await GetJohnsWalletWithMoney(); diff --git a/MangoPay.SDK/Core/APIs/ApiBase.cs b/MangoPay.SDK/Core/APIs/ApiBase.cs index cab6b4a1..48e3ff11 100644 --- a/MangoPay.SDK/Core/APIs/ApiBase.cs +++ b/MangoPay.SDK/Core/APIs/ApiBase.cs @@ -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 { @@ -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)}, diff --git a/MangoPay.SDK/Core/APIs/ApiPayIns.cs b/MangoPay.SDK/Core/APIs/ApiPayIns.cs index 110dfade..7e3067d2 100644 --- a/MangoPay.SDK/Core/APIs/ApiPayIns.cs +++ b/MangoPay.SDK/Core/APIs/ApiPayIns.cs @@ -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 @@ -175,6 +174,17 @@ public async Task CreateGiropayWebAsync(PayInGiropayWebPostD MethodKey.PayinsGiropayWebCreate, payIn, idempotentKey); } + /// Creates new payin Swish web. + /// Idempotent key for this request. + /// Object instance to be created. + /// Object instance returned from API. + public async Task CreateSwishWebAsync(PayInSwishWebPostDTO payIn, + string idempotentKey = null) + { + return await this.CreateObjectAsync( + MethodKey.PayinsSwishWebCreate, payIn, idempotentKey); + } + /// Creates new payin bancontact web. /// Idempotent key for this request. /// Object instance to be created. @@ -337,6 +347,14 @@ public async Task GetGiropayAsync(string payInId) return await this.GetObjectAsync(MethodKey.PayinsGet, entitiesId: payInId); } + /// Gets PayIn Swish entity by its identifier. + /// PayIn identifier. + /// PayIn object returned from API. + public async Task GetSwishAsync(string payInId) + { + return await this.GetObjectAsync(MethodKey.PayinsGet, entitiesId: payInId); + } + /// Gets PayIn Bancontact entity by its identifier. /// PayIn identifier. /// PayIn object returned from API. diff --git a/MangoPay.SDK/Core/Enumerations/MethodKey.cs b/MangoPay.SDK/Core/Enumerations/MethodKey.cs index f9d16693..84fb3cd6 100644 --- a/MangoPay.SDK/Core/Enumerations/MethodKey.cs +++ b/MangoPay.SDK/Core/Enumerations/MethodKey.cs @@ -46,6 +46,7 @@ public enum MethodKey PayinsSatispayWebCreate, PayinsBlikWebCreate, PayinsKlarnaWebCreate, + PayinsSwishWebCreate, PayinsIdealWebCreate, PayinsGiropayWebCreate, PayinsBancontactWebCreate, diff --git a/MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs b/MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs index 6da3b898..51cf2a2f 100644 --- a/MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs +++ b/MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs @@ -38,19 +38,29 @@ public enum PayInPaymentType /// Mbway payment type MBWAY, + /// Multibanco payment type MULTIBANCO, + /// Satispay payment type SATISPAY, + /// Blik payment type BLIK, + /// Klarna payment type KLARNA, + /// Ideal payment type IDEAL, + /// Giropay payment type GIROPAY, + /// Bancontact payment type - BCMC + BCMC, + + /// Swish payment type + SWISH } } diff --git a/MangoPay.SDK/Entities/GET/PayInSwishWebDTO.cs b/MangoPay.SDK/Entities/GET/PayInSwishWebDTO.cs new file mode 100644 index 00000000..74162b87 --- /dev/null +++ b/MangoPay.SDK/Entities/GET/PayInSwishWebDTO.cs @@ -0,0 +1,30 @@ +namespace MangoPay.SDK.Entities.GET +{ + public class PayInSwishWebDTO: PayInDTO + { + /// An optional value to be specified on the user's bank statement. + public string StatementDescriptor { get; set; } + + /// The URL to redirect to after the payment, whether the transaction was successful or not + public string ReturnURL { get; set; } + + /// The URL to which the user is redirected to complete the payment + public string RedirectURL { get; set; } + + /// The mobile URL to which to redirect the user to complete the payment in an app-to-app flow. + public string DeepLinkURL { get; set; } + + /// The PNG file of the Swish QR code as a Base64-encoded string. + public string QRCodeURL { get; set; } + + /// + ///

Allowed values: WEB, APP

+ ///

Default value: WEB

+ ///

The platform environment of the post-payment flow. The PaymentFlow value combines with the ReturnURL to manage the redirection behavior after payment:

+ ///

Set the value to APP to send the user to your platform’s mobile app

+ ///

Set the value to WEB to send the user to a web browser

+ ///

In both cases you need to provide the relevant ReturnURL, whether to your app or website.

+ ///
+ public string PaymentFlow { get; set; } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/Entities/POST/PayInSwishWebPostDTO.cs b/MangoPay.SDK/Entities/POST/PayInSwishWebPostDTO.cs new file mode 100644 index 00000000..50eaaab0 --- /dev/null +++ b/MangoPay.SDK/Entities/POST/PayInSwishWebPostDTO.cs @@ -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; + } + + /// Author identifier. + public string AuthorId { get; set; } + + /// Debited funds. + public Money DebitedFunds { get; set; } + + /// Fees. + public Money Fees { get; set; } + + /// Credited wallet identifier. + public string CreditedWalletId { get; set; } + + /// The URL to redirect to after the payment, whether the transaction was successful or not + public string ReturnURL { get; set; } + + /// An optional value to be specified on the user's bank statement. + public string StatementDescriptor { get; set; } + + /// + ///

Allowed values: WEB, APP

+ ///

Default value: WEB

+ ///

The platform environment of the post-payment flow. The PaymentFlow value combines with the ReturnURL to manage the redirection behavior after payment:

+ ///

Set the value to APP to send the user to your platform’s mobile app

+ ///

Set the value to WEB to send the user to a web browser

+ ///

In both cases you need to provide the relevant ReturnURL, whether to your app or website.

+ ///
+ public string PaymentFlow { get; set; } + } +} \ No newline at end of file