|
|
|
|
@@ -4,10 +4,6 @@ using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Darkmatter.Fonepay
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Public facade. Auto-loads config + secrets via <see cref="FonepayConfig.Load"/>.
|
|
|
|
|
/// Caller never touches credentials.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class FonepayClient
|
|
|
|
|
{
|
|
|
|
|
private readonly FonepayApiClient _api;
|
|
|
|
|
@@ -22,41 +18,25 @@ namespace Darkmatter.Fonepay
|
|
|
|
|
_api = new FonepayApiClient(config, signer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Request a new QR code. The returned URL is valid for 15 minutes. Call GetStatusAsync() to check if the QR code has been paid.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <param name="ct"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Task<QrResult> PurchaseAsync(QrRequest req, CancellationToken ct = default)
|
|
|
|
|
=> _api.PostQRAsync(req, ct);
|
|
|
|
|
public FonepayAsync<QrResult> PurchaseAsync(QrRequest req, CancellationToken ct = default)
|
|
|
|
|
=> FonepayAsyncBridge.Wrap(_api.PostQRAsync(req, ct), ct);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check if a QR code has been paid. Call after PostQRAsync() to check if the QR code has been paid. Returns "PAID" if successful, "UNPAID" if not yet paid, or an error message if the PRN is invalid or expired.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="prn"></param>
|
|
|
|
|
/// <param name="ct"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Task<QrResult> GetStatusAsync(string prn, CancellationToken ct = default)
|
|
|
|
|
=> _api.GetStatusAsync(prn, ct);
|
|
|
|
|
public FonepayAsync<QrResult> GetStatusAsync(string prn, CancellationToken ct = default)
|
|
|
|
|
=> FonepayAsyncBridge.Wrap(_api.GetStatusAsync(prn, ct), ct);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Request a tax refund. Returns "REFUND_SUCCESS" if successful, or an error message if the PRN is invalid, expired, or not eligible for refund.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
/// <param name="ct"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Task<TaxRefundResponse> PostTaxRefundAsync(TaxRefundRequest req, CancellationToken ct = default)
|
|
|
|
|
=> _api.PostTaxRefundAsync(req, ct);
|
|
|
|
|
public FonepayAsync<TaxRefundResponse> PostTaxRefundAsync(TaxRefundRequest req, CancellationToken ct = default)
|
|
|
|
|
=> FonepayAsyncBridge.Wrap(_api.PostTaxRefundAsync(req, ct), ct);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Connects to the QR websocket and awaits the terminal payment frame, then auto-disconnects.
|
|
|
|
|
/// Pass <see cref="QrResult.thirdpartyQrWebSocketUrl"/> from <see cref="PurchaseAsync"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public async Task<QRPaymentStatus> AwaitPaymentAsync(
|
|
|
|
|
public FonepayAsync<QRPaymentStatus> AwaitPaymentAsync(
|
|
|
|
|
string websocketUrl,
|
|
|
|
|
Action<bool> onQrVerified = null,
|
|
|
|
|
CancellationToken ct = default)
|
|
|
|
|
=> FonepayAsyncBridge.Wrap(AwaitPaymentInternalAsync(websocketUrl, onQrVerified, ct), ct);
|
|
|
|
|
|
|
|
|
|
private async Task<QRPaymentStatus> AwaitPaymentInternalAsync(
|
|
|
|
|
string websocketUrl,
|
|
|
|
|
Action<bool> onQrVerified,
|
|
|
|
|
CancellationToken ct)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(websocketUrl))
|
|
|
|
|
throw new ArgumentException("Websocket URL required", nameof(websocketUrl));
|
|
|
|
|
|