Skip to content

Latest commit

 

History

History
97 lines (60 loc) · 3.15 KB

README.md

File metadata and controls

97 lines (60 loc) · 3.15 KB

Payment Module

Payment module provides an API to make payments via using PayPal easily.

Installation

TODO

Usage

  1. Create a Payment Request via using IPaymentRequestAppService

  2. Build an URL to redirect to checkout page via using IPaymentUrlBuilder

    public class MyPageModel : AbpPageModel
    {
        protected IPaymentRequestAppService PaymentRequestAppService { get; }
        protected IPaymentUrlBuilder PaymentUrlBuilder { get; }
    
        public MyPageModel(
            IPaymentRequestAppService paymentRequestAppService,
            IPaymentUrlBuilder paymentUrlBuilder)
        {
            PaymentRequestAppService = paymentRequestAppService;
            PaymentUrlBuilder = paymentUrlBuilder;
        }
    
        public async Task OnPostAsync()
        {
            var paymentRequest = await PaymentRequestAppService.CreateAsync(new PaymentRequestCreationDto
            {
                Amount = 9.90m,
                CustomerId = CurrentUser.Id.ToString(),
                ProductId = "UniqueProductId",
                ProductName = "Awesome Product"
            });
    
            var checkoutUrl = PaymentUrlBuilder.BuildCheckoutUrl(paymentRequest.Id).AbsoluteUri;
    
            Response.Redirect(checkoutUrl);
        }
    }

Distributed Events

  • Payment.Completed (PaymentRequestCompletedEto): Published when a payment is completed. Completion can be triggered via webhook or callback. Source doesn't affect to the event. Event will be triggered once.
    • PaymentRequestId: Represents PaymentRequest entity Id.
    • ExtraProperties: Represents ExtraProperties of PaymentRequest entity. You can use this properties to find your related objects to that payment.
  • Payment.Failed(PaymentRequestFailedEto): Published when a payment is failed.
    • PaymentRequestId: Represents PaymentRequest entity Id.
    • FailReason: Reason of failure from payment provider (PayPal)
    • ExtraProperties: Represents ExtraProperties of PaymentRequest entity.

Webhook Handling

You have to make some configuration for webhooks on PayPal Dashboard.

If you test it locally, you can use ngrok to open your localhost to world

  1. Deploy eventhub or open your ip:port to public. Your HttpApi.Host must be accessible from all over the world.

  2. Go to Application List. Find your app and go details. (You can use my account below)

PayPal Account Credentials

[email protected] 1q2w3E**

Use following temp number for two factor authentication verification: https://receive-smss.com/sms/48722717428/

(Yes the star (*) is doubled. min password length requirement was 8)

  1. At the bottom of page you'll see the Webhooks section image

  2. Click to Add Webhook button and use following values:

    • Webhook URL: https://yourhttpapihosturl.com/api/payment/requests/webhook (replace hostname with your API public url)
    • Event types: Checkout order approved, Checkout order completed