Skip to content

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

License

Notifications You must be signed in to change notification settings

JamoCA/cfml-paypal-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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>");

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published