I was able to do a workaround for this issue: I do not know if this is the proper way to do this, but I am no longer receiving the original error. First, I created several hidden fields to the corresponding items that I wanted to be posted, along with giving every input an id - the following are the hidden fields: <input
type="text"
[(ngModel)]="model.total"
style="padding-bottom: 10px;"
name="total"
id="total"
#total="ngModel"
value="{{ model.total | currency }}"
/>
<input
type="hidden"
name="user_id"
id="user_id"
value="{{ this.user_id }}"
/>
<input
type="hidden"
name="orders_id"
id="orders_id"
value="{{ this.orders_id }}"
/>
<input
type="hidden"
name="product"
id="product"
value="{{ this.product }}"
/>
<input
type="hidden"
name="subTotal"
id="subTotal"
value="{{ this.payPalSrvc.getSubTotal() }}"
/> Second, I created a separate PayPalService, to separate functionality, along with, I wanted these posts and gets to go through my interceptor to place jwt in the headers: import { Injectable } from "@angular/core";
import { HttpClient, HttpHeaders, HttpResponse } from "@angular/common/http";
import { ShoppingCartService } from "./shopping-cart.service";
import { ProductService } from "./product.service";
import { LoginService } from "./login.service";
@Injectable({
providedIn: "root"
})
export class PaypalService {
constructor(
private http: HttpClient,
private loginSrvc: LoginService,
private prdSrvc: ProductService,
private cartSrvc: ShoppingCartService
) {}
addScript = false;
paypalLoad = true;
finalAmount;
subTotal;
paypalConfig = {
env: "sandbox",
client: {
sandbox:
"<my-sandbox-id>",
production: "<your-production-key here>"
},
commit: true,
payment: function(data, actions) {
return actions.payment.create({
transactions: [
{
amount: {
total: document.getElementById("total").value,
currency: "USD",
details: {
subtotal: document.getElementById("subTotal").value,
tax: (document.getElementById("total").value * 0.07).toFixed(2),
shipping: (document.getElementById("total").value * 0.03).toFixed(2),
handling_fee: "1.00",
shipping_discount: "0.00",
insurance: (document.getElementById("total").value * 0.01).toFixed(2)
}
},
description: "The payment from for-her application.",
/* custom: "90048630024435", */
invoice_number: document.getElementById("orders_id").value, // Insert a unique invoice number
payment_options: {
allowed_payment_method: "INSTANT_FUNDING_SOURCE"
},
soft_descriptor: document.getElementById("user_id").value,
item_list: {
items: [document.getElementById("product").value],
shipping_address: {
recipient_name: (document.getElementById("firstName").value + " " + document.getElementById("lastName").value),
line1: document.getElementById("address").value,
line2: document.getElementById("address2").value,
city: document.getElementById("city").value,
country_code: document.getElementById("country").value,
postal_code: document.getElementById("zip").value
phone: document.getElementById("phone").value,
state: document.getElementById("state").value,
email: document.getElementById("email").value
}
}
}
],
note_to_payer: "Contact us for any questions on your order."
});
},
onAuthorize: (data, actions) => {
return actions.payment.execute().then(payment => {
// Do something when payment is successful.
// window.alert("Thank you for your purchase! You order will be processed and shipped as soon as possible");
document.getElementById("myModal").style.display = "block";
document.getElementById("ModalBackdrop").style.display = "block";
this.cartSrvc.postCart();
});
}
};
addPaypalScript() {
this.addScript = true;
return new Promise((resolve, reject) => {
const scripttagElement = document.createElement("script");
scripttagElement.src="https://www.paypalobjects.com/api/checkout.js";
scripttagElement.onload = resolve;
document.body.appendChild(scripttagElement);
});
}
public getSubTotal() {
this.subTotal = (document.getElementById("total").value) -
((document.getElementById("total").value * 0.07) +
(document.getElementById("total").value * 0.03) +
(document.getElementById("total").value * 0.01) +
1.00);
return this.subTotal.toFixed(2);
}
public getToken(): string {
return localStorage.getItem("jwt");
}
} With that said, you can also see that I have a new error, which I do not understand why I am receiving it, as I pasted the JSON validator and it responded with validating the JSON - see screen shots: The following is a new error, which I am sure that I should have to create another post, but at least if someone else was going through the same thing, then they can at least move forward: Error: Request to post https://www.sandbox.paypal.com/v1/payments/payment failed with 400 error. Correlation id: f31569c675597, f31569c675597
{
"name": "MALFORMED_REQUEST",
"message": "Incoming JSON request does not map to API request",
"information_link": "https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST",
"debug_id": "f31569c675597"
}
request/</<@https://www.paypalobjects.com/api/checkout.js:14216:39
... View more