Question

We are using Paypal Pro to do direct credit card processing. What happens when I put 2 transactions in a request, and the credit card approves one transaction object, but declines the other because of lack of funds. Does PayPal throw away the entire transaction and returns an error?

Take the following code straight from paypals rest api for node.js

var payment_details = {
  "intent": "sale",
  "payer": {
    "payment_method": "credit_card",
    "funding_instruments": [{
      "credit_card": {
        "type": "visa",
        "number": "4417119669820331",
        "expire_month": "11",
        "expire_year": "2018",
        "cvv2": "874",
        "first_name": "Joe",
        "last_name": "Shopper",
        "billing_address": {
          "line1": "52 N Main ST",
          "city": "Johnstown",
          "state": "OH",
          "postal_code": "43210",
          "country_code": "US" }}}]},
  "transactions": [{
    "amount": {
      "total": "7.47",
      "currency": "USD",
      "details": {
        "subtotal": "7.41",
        "tax": "0.03",
        "shipping": "0.03"}},
    "description": "This is the payment transaction description." }]};

paypal_sdk.payment.create(payment_details, function(error, payment){
  if(error){
    console.error(error);
  } else {
    console.log(payment);
  }
});

What happens when we put 2 transaction objects in there, will we have to handle the case of the credit card declining on the second transaction?

Was it helpful?

Solution

This is what we ended up using. We used the items feild to tell paypal about the multiple items in the transaction. Items is an array of items:

items.push({
    quantity: "1",
    name: classList[i].name,
    price: price.toFixed(2),
    currency: "USD"
});

var create_payment_json = {
    "intent": "sale",
    "payer": {
        "payment_method": "paypal"
    },
    "redirect_urls": {
        "return_url": "http://"+config.host+"/payment/success/"+paymentId,
        "cancel_url": "http://"+config.host+"/payment/cancel/"+paymentId
    },
    "transactions": [{
        "item_list": {
            "items": items
        },
        "amount": {
            "currency": "USD",
            "total": (total.toFixed(2))
        },
        "description": description
    }]
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top