-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzPayPal.cs
50 lines (45 loc) · 1.83 KB
/
AzPayPal.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Configuration;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;
namespace com.businesscentral
{
public static class AzPayPal
{
[FunctionName("AzPayPal")]
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
HttpRequest req,
ILogger log,
ExecutionContext context)
{
log.LogInformation("Request notified");
// Load configuration
var configBuilder = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var config = new ConnectorConfig(configBuilder);
if (!req.Method.Equals("GET"))
throw new HttpResponseException(HttpStatusCode.BadRequest);
var orderID = req.Query["orderID"].ToString();
if (String.IsNullOrEmpty(orderID))
throw new HttpResponseException(HttpStatusCode.BadRequest);
var composer = new MessageComposer(config, log);
var html = composer.DataBindPayPalPage(orderID);
var response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StringContent(html);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
return response;
}
}
}