Skip to content

Latest commit

 

History

History
78 lines (63 loc) · 2.47 KB

README.md

File metadata and controls

78 lines (63 loc) · 2.47 KB

cfml-paypal-rest-api

ColdFusion/CFML CFC for transacting a credit card using PayPal REST API with Advanced Credit and Debit Card Payments.

Important: You'll need a PayPal Business account to do the following:

  • Go live with integrations.
  • Test integrations outside the US.

Here's how to get your client ID and client secret:

  • Select Log in to Dashboard and log in or sign up.
  • Select Apps & Credentials.
  • New accounts come with a Default Application in the REST API apps section. To create a new project, select Create App.
  • View app details and enable "Advanced Credit and Debit Card Payments"
  • Copy the client ID and client secret for your app.
  • Using "Live mode" requires approval from PayPal, but you can test using the sandbox.

1. Initialize the CFC

payPalApi = new PaypalRestAPI(
	clientId = "[PayPal API ClientID]",
	clientSecret = "[PayPal API Secret]",
	descriptor = "My Big Business Name", // <= 22 chars; printed on CC statement
	developmentMode = true
);

2. Create a Unique ID

// REQUIRED: create unique ID for tracking order
requestId = createuuid();

3. Create an Order

order = payPalApi.createOrder(
	requestId = requestId
	amount = 14.99
);

isCreated = len(order.id) && order.status eq "created";

if (!isCreated){
	writeoutput("<p style=""color:red;""><b>Order Error:</b> #order.errorMessage#</p>");
	// Redisplay form to allow corrections
	exit;
}

4. Capture the Order (if the order creation was successful)

capturedOrder = payPalApi.captureOrder(
	requestId = requestId,
	id = order.id,
	name = "Joe Cardholder",
	cardnumber = "4556747948786484",
	expdate = dateadd("m", 2, now()), // format "yyyy-mm" or pass a date object
	cvv2 = "789",
	address = "123 ABC Street", // optional
	city = "Anytown", // optional (admin_area_2)
	state = "CA", // optional  (admin_area_1)
	zip = "90210", // optional (postal_code)
	country = "US" // optional
);

isCaptured = capturedOrder.responseCodeText eq "Approved" && capturedOrder.status eq "completed";

if (!isCaptured){
	writeoutput("<p style=""color:red;""><b>Capture Error:</b> #capturedOrder.errorMessage#</p>");
	// Redisplay form to allow corrections
	exit;
}
// Save the order data.
writeoutput("<p>Paypal Transaction ID #capturedOrder.transactionId#.</p>");