Skip to content

Conversation

Kevded
Copy link
Contributor

@Kevded Kevded commented May 18, 2017

Use Paypal-rest-sdk on firebase functions
paypal-rest-sdks

Copy link
Contributor

@nicolasgarnier nicolasgarnier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this sample @Kevded , it's a nice one! I have added a few comments, would be nice if you could resolve them!

Cheers!

// Configure your environment
paypal.configure({
'mode': 'sandbox', // sandbox or live
'client_id': 'your_client_id', // replace your_client_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you replace 'your_cliend_id' by functions.config().paypal.client_id and add instrucitons to set this environment variable in the README (i.e. users have to run: firebase functions:config:set paypal.client_id="yourPaypalClientID" paypal.client_secret="yourPaypalClientSecret")?

paypal.configure({
'mode': 'sandbox', // sandbox or live
'client_id': 'your_client_id', // replace your_client_id
'client_secret': 'your_client_secret' // replace your_client_secret
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you replace 'your_cliend_id' by functions.config().paypal.client_secret ?

res.setHeader('Content-Type', 'application/json');
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Headers', 'application/json, Content-Type');
res.setHeader('Access-Control-Allow-Methods', 'POST');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use the cors ExpressJS middleware here instead of setting all the headers manually? See an example here: https://github.com/firebase/functions-samples/blob/master/quickstarts/time-server/functions/index.js#L57

'client_secret': 'your_client_secret' // replace your_client_secret
});

exports.pay = functions.https.onRequest((req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comment above explaining what the Functions does?

// example url https://us-central1-<project-id>.cloudfunctions.net/process
// replace return_url, cancel_url
redirect_urls: {
return_url: 'https://us-central1-<project-id>.cloudfunctions.net/process',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get the project ID from: process.env.GCLOUD_PROJECT so please replace with:

return_url: `https://us-central1-${process.env.GCLOUD_PROJECT}.cloudfunctions.net/process`,
payer_id: req.query.PayerID
};

paypal.payment.execute(paymentId, payerId, function (error, payment) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an arrow function here :)


paypal.payment.execute(paymentId, payerId, function (error, payment) {
if (error) {
console.error(JSON.stringify(error));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just console.error(error);

paypal.payment.execute(paymentId, payerId, function (error, payment) {
if (error) {
console.error(JSON.stringify(error));
res.redirect('http://localhost:4200/error');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change that URL to a production URL ?

} else {
console.warn('payment.state: not approved ?');
// replace debug url
res.redirect('https://console.firebase.google.com/project/<project-id>/functions/logs?search=&severity=DEBUG');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace the project ID automatically here as shown above.

});

// Complete the payment
exports.process = functions.https.onRequest((req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a little bit more details in the comment here to explain a bit more what this function does?

@nicolasgarnier
Copy link
Contributor

ping :)

@nicolasgarnier nicolasgarnier self-assigned this Jun 29, 2017
@Kevded
Copy link
Contributor Author

Kevded commented Jun 29, 2017 via email

@nicolasgarnier
Copy link
Contributor

Thanks @Kevded I've updated the README with more detailed step-by-step instructions.

Do you think it would be possible for you to also commit a small web UI like the one you showed in the animated GIF? this would make the sample so much more complete! PS if you do don't forget about this feature: https://firebase.google.com/docs/hosting/functions this will allow you to have the Paypal Cloud Function on the same domain as the web UI.

@Kevded
Copy link
Contributor Author

Kevded commented Jul 21, 2017

I tried to pass the uid value via the optional "custom" field in the "transaction" object as in paypal https://developer.paypal.com/docs/api/payments/#definition-transaction, but this does not work, so I have passed through the "description" field.

@@ -0,0 +1,3 @@
module.exports = {
"extends": "google"
}; No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove that file fro the PR?

"constructor-super": "warn",
"valid-typeof": "warn"
}
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove that file from the PR ?


// Custom Globals
"globals" : {} // additional predefined global variables
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove that file from the PR?

paypal-functions@ /home/dsv/WebstormProjects/functions-samples/paypal/functions
├── eslint@4.1.1
└── eslint-config-google@0.8.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove that file from the PR?

@@ -0,0 +1,102 @@
'use strict';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'client_secret': functions.config().paypal.client_secret // run: firebase functions:config:set paypal.client_secret="yourPaypalClientSecret"
});

exports.pay = functions.https.onRequest((req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a commenbt describing what the function does, what is expected as body in the request etc...


exports.pay = functions.https.onRequest((req, res) => {
// Dev
cors(req, res, () => {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

}
}
});
}); No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add line at the end of the file.

"description": "Paypal Firebase Functions",
"dependencies": {
"cors": "^2.8.3",
"eslint": "^4.1.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove eslint stuff from dependency and devDependency?

<a disabled class="mdl-button mdl-js-button mdl-button--raised" href="/">Home</a>
</body>

</html> No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a trailing line at the end of the file ? :)

</div>
</body>

</html> No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a line at the end of the file.

@nicolasgarnier
Copy link
Contributor

I added a few style fixes and we should be all set :)

@nicolasgarnier nicolasgarnier merged commit 24672ea into firebase:master Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants