I'm trying to create a Stripe checkout session in Business Central. but I'm facing an issue with passing the content type as "application/x-www-form-urlencoded". I've tried setting the header header.Add('Content-Type', 'application/x-www-form-urlencoded')
but I'm facing this error.
This is my Code..procedure StripeAPI()
Var
client: HttpClient;
cont: HttpContent;
header: HttpHeaders;
response: HttpResponseMessage;
Jobject: JsonObject;
tmpString: Text;
TypeHelper: Codeunit "Type Helper";
granttype: text;
clienid: text;
username: text;
password: text;
Begin
CancelURL1 := 'https://example.com';
success_url1 := 'https://example.com';
line_items_currency1 := 'usd';
line_items_Nam := 'Shirt';
line_items_unitAmoun := '2000';
LineAmountQuantit := '1';
Mode1 := 'payment';
PaymentMethodType1 := 'card';
tmpString := 'mode=' TypeHelper.UrlEncode(Mode1) '&line_items[0][price_data][unit_amount]=' TypeHelper.UrlEncode(line_items_unitAmoun) '&cancel_url=' TypeHelper.UrlEncode(CancelURL1) '&success_url=' TypeHelper.UrlEncode(success_url1) '&line_items[0][price_data][currency]=' TypeHelper.UrlEncode(line_items_currency1) '&line_items[0][price_data][product_data][name]=' TypeHelper.UrlEncode(line_items_Nam) '&line_items[0][quantity]=' TypeHelper.UrlEncode(LineAmountQuantit) '&payment_method_types[0]=' TypeHelper.UrlEncode(PaymentMethodType1);
Message(tmpString);
cont.WriteFrom(tmpString);
cont.ReadAs(tmpString);
cont.GetHeaders(header);
header := client.DefaultRequestHeaders;
header.Add('charset', 'UTF-8');
header.Remove('Content-Type');
header.Add('Content-Type', 'application/x-www-form-urlencoded');
header.Add('Authorization', 'Bearer *********************************************');
client.Post('**********************', cont, response);
response.Content.ReadAs(responseText);
end;
I have also checked that the tmpString
a variable that contains the data in the text format url embedded and it is working fine in Postman when selecting "application/x-www-form-urlencoded".
can you guys help me..
Regards