i am trying to connec to paypal

86 Views Asked by At

I am trying to connect to the paypal but i have some questions with regards to the form data i need to pass, paypal expects it like this

"purchase_units": [
    {
      "amount": {
        "currency_code": "USD",
        "value": "100.00"
      }
    }
  ]

but the form just passes the amount > currencycode > value

so how can i convert the form scope to this type of data which paypal expects, same is the case with other data if i need to send, this is driving me nuts

2

There are 2 best solutions below

1
On BEST ANSWER

What PayPal expects is JSON, which is one of the most common formats for sending data between systems in today's web.

You mentioned a form scope, which must be a coldfusion thing. Are you doing a server or "client-side only" integration? Client-side only is very basic, just spit this HTML/JS out to the browser: https://developer.paypal.com/demo/checkout/#/pattern/client

The server-based version is more involved, you will need to communicate with the PayPal API endpoints directly from your server. There are SDKs and guides for a number of more common server-side languages, which you might find adaptable to your purposes -- see 'Set Up Transaction' and 'Capture Transaction' here: https://developer.paypal.com/docs/checkout/reference/server-integration/

1
On

This is a more a long comment than an answer, but here goes. Are you trying to do something like this?

<cfscript>
form.value =4

data = { "purchase_units" : [
    {
      "amount": {
        "currency_code": "USD",
        "value": "#form.value#"
      }
    }
  ]
}

writedump(serializeJSON(data))
</cfscript>

Live version: https://cffiddle.org/app/file?filepath=c5a0ae3e-e24e-462c-8828-a46da98b9ace/2cea5311-965d-4f9c-af0f-7a0a29563e26/20e07958-06f1-41b2-937c-2c98c819a7a2.cfm