Integrate rave flutterwave api in php - php

hello I am using core PHP in client Project, I need to integrate rave flutter wave API, I have searched a lot of links
now I am checking this URL here but not getting a good result,
so please help me in rave flutter wave "Nigeria payment gateway" API in PHP

Our Product for collections is called Rave, please follow the steps below to get started:
Sign up https://ravepay.co/ , for a sanbox account sign up on http://rave.frontendpwc.com
Add a settlement account on sign up
Select a settlement preference by navigating to Account settings > Settlement preference (Find documentation attached for more detailed instruction).
Documentation for developers: https://flutterwavedevelopers.readme.io/v1.0
Pay Now
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById("submit").addEventListener("click", function() {
var chargeResponse = "",
trxref = "FDKHGK" + Math.random(),// add your transaction ref here
pubkey = "XXXX"; // Add public keys generated on your dashboard here
getpaidSetup({
customer_email: "xxxxx",//
amount: 1000,
currency: "NGN",
country: "NG",
custom_logo: "http://imgur.com/uuRnkV9",
custom_description:"",
custom_title: "The Start",
txref: trxref,
PBFPubKey: pubkey,
onclose: function(response) {},
callback: function(response) {
//flw_ref = response.tx.flwRef;
console.log("This is the response returned after a charge", response);
if(response.tx.chargeResponse =='00' || response.tx.chargeResponse == '0') {
// redirect to a success page
} else {
// redirect to a failure page.
}
}
});
});
});
If you have any issues at any point, please let us know and we will help sort you out.

If you are here in 2020, the docs for the payment gateway has been updated, you can check how to integrate this with laravel seamlessly using this link
https://questionbump.com/question/how-can-i-setup-flutterwave-payment-webhook-successfully-on-laravel-5/
I hope it helps someone. I struggled to get this working.

Related

How to validate using Paypal API v2 in client side

We currently using checkout.js from paypal when doing payments, everything works well and we want now to upgrade to v2 of paypal api.
below is our code using checkout.js
https://jsfiddle.net/hxm0cjbp/
paypal.Button.render({
style: {
// style here
},
env: variable_here,
client: {
sandbox: variable_here,
production: variable_here
},
commit: true,
validate: function (actions) {
// problem occur from here in v2
// by using actions.disable();
functionToDisableButtonIfValidationFail();
},
onClick: function () {
// more functions here
},
payment: function (data, actions) {
// more functions here
},
onAuthorize: function (data, actions) {
// more functions here
}
}, '#selector_here');
below is our new code using v2.
https://jsfiddle.net/sk3rpme5/
paypal.Buttons({
validate: function(){
// problem occur from here
// actions.disable() is not recognize anymore
functionToDisableButtonIfValidationFail();
},
createOrder: function() {
// function here
}
}).render('#selector_here');
the error starts in validate method.
In using v1, when clicking the paypal button. If validation fails, it will show form errors. In v2, when clicking the paypal button. The paypal redirect page still shows and the form errors too. We would like to work it out like v1, show only the paypal page if validation is correct. When checking the SDK, it looks like validate was removed.

How to get data from fitbit using PHP

I'm trying to get user data from fitbit using fitbit api but the process seems confusing to me. I have tried several ways but could not succeed. I have searched in the internet for solution and found this
http://www.staze.org/retrieving-steps-data-fitbit-api/
But this process is also not working for me.
How to fix the code I mentioned to get data from fitbit or is there any other way to get data using PHP?
You need to do lot of homwwork Dude ;) Anyways...
To access Fitbit Data you can use OAuth 2.0 authentication
You need to pass tokenType and accessCode in any ajax call and you will get response
Now to get accessCode you need to register an App on Fitbit site
You can read API doc for more details
Here is sample code how to access Fitbit Profile using tokenType and accessCode
and I can assure you this is working Code so if your code doesnt work
it means you are doing somthing wrong in above steps
function getProfile() {
var authCode = token_type + " " + access_token;
$.ajax({
url: "https://api.fitbit.com/1/user/-/profile.json",
type: "GET",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", fitbitAccessCode);
},
success: function(jsonObject) {
// logic ...
},
error: function(error) {
alert("Error");
}
});
}

PayPal Express Checkout, update database on successful payment

Introduction
I´ve been looking at integrating a somewhat big project of mine with PayPal Express Checkout, and use that as the main system to handle payments on my site. Although their documentation is quite extensive, I really can´t find too good a place to start. Over the past few days, I´ve been presented with headache upon headache, in attempt to figure out how on Earth to integrate my site, as well as its database, with PayPal Express Checkout.
Summary
The JavaScript bit is pretty straight forward, and charging money using the client-side integration is extremely easy. But I also need a way to update fields in my database upon a payment going through (being successful), and from what I´ve understood so far, that can only be done by using the advanced server integration.
Problem
The problem, given the aforementioned reasons, is somehow managing to implement the advanced server integration solution, into my platform, in order to make way for changes in the database to occur upon a transaction being successful.
As mentioned before, the PayPal documentation is fairly extensive--problem is, I´ve never really went over using REST API´s, and it appears as though integrating what I´m after can only really be done using the PayPal REST API, to verify that the payment(s) have taken place.
Question
With all that being said, what I need help with is finding some place in all of this to start. I´m aware StackOverflow may not be the best place for a question like this, but it appears lots of people are having trouble with this exact question, and it´s an essential part of settings up any business on the web to get this to work.
Any pointers on where to start, or anything relating to the subject other than the PayPal documentation would be extremely helpful.
What follows is a minimal way to use Express Checkout with a server-side Payments REST API integration, including the associated code for client and server in JavaScript. I hope it helps.
You'll need to login to developer.paypal.com and create a REST API app. Your new app will be assigned a Client ID and Secret which you can use to request access tokens, which authorize your use of the PayPal REST API. The only app setting you need for what follows here is "Accept Payments". Sandbox accounts for testing are automatically created when you create an app.
Your (checkout) page loads PayPal's Express Checkout script, and a script you write renders a PayPal button:
// In your script:
paypal.Button.render({
env: 'sandbox', // Or 'production'.
commit: true, // Show 'Pay Now' button.
style: { // Style the button.
size: 'responsive',
color: 'silver',
shape: 'rect'
},
payment: function(data, actions) {
// See step 3.
},
onAuthorize: function(data, actions) {
// See step 7.
}
}, '#paypal-button');
Your customer clicks the rendered PayPal checkout button.
The payment function you define in the argument you give to paypal.Button.render() is called by PayPal's script, which sends a request to your server with your payload. Your payload contains (for example) cart contents and its associated data.
paypal.Button.render({
// ...
payment: function(data, actions) {
return paypal.request(
{
method: 'post',
url: '/your-api/create-payment',
json: {
order: items,
or: whatever
}
}
).then(
function(res) {
// Return the payment id received from your server.
return res.paymentId;
}
).catch(
function(err) {
// Oops, foobared.
}
);
},
// ...
}
Your server sends a request to api.sandbox.paypal.com, with your access token, to create a payment. When your server receives the newly created payment data from PayPal it (perhaps) persists the data on your server, but it must return the payment id to the client.
// HTTP request data for creating a payment.
{
method: 'post',
// Remove '.sandbox' below to use production endpoint.
url: 'https://api.sandbox.paypal.com/v1/payments/payment';
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + 'your access token here'
},
data: {
// Allows immediate payments with PayPal and credit cards in
// the Express Checkout dialog.
intent: 'sale',
// I suppose these were required by other PayPal REST services,
// but they won't be used because, for Express Checkout, you
// handle the confirmation/cancellation flow yourself, on the
// client.
redirect_urls: {
return_url: 'https://...'
cancel_url: 'https://...'
},
payer: {
payment_method: 'paypal',
},
note_to_payer: 'Thanks, you\'re magnificently awesome!',
transactions: [{
amount: {
total: total, // Your computed total.
currency: 'USD',
details: {
subtotal: subtotal, // Your computed subtotal.
tax: tax, // Your computed tax.
shipping: shipping // Your computed shipping.
// Other parameters are available for your use.
}
},
item_list: {
items: [
{
name: 'shinny shirt of mithril mail',
description: 'shinny',
sku: '12345',
quantity: 1,
price: 1.00,
currency: 'USD'
}
],
// Some properties aren't required, like this one.
shipping_method: 'USPS'
},
description: 'Your PayPal payment for a shinny shirt of mithril mail.',
// Not required and can be added later by patching the
// payment: maybe you don't want to add an invoice to and
// order until the payment is approved.
invoice_number: 12345
}]
}
}
The payment function you provided then receives the payment id from your server and uses it as its return value.
// See return value in step 3.
And now the Express Checkout payment dialog pops up for your customer, who must login in and confirm the payment, create an account, or checkout with a credit/debit card.
After the customer confirms payment by clicking the Pay Now button in the Express Checkout dialog, the onAuthorize function you define in the argument you give to paypal.Button.render() is called by PayPal's script. You can use this function's actions parameter to get() payment information from PayPal, which you can use in a confirmation page, etc. Use its data parameter to get the payment id and payer id, which must be sent in a request to your server to execute the payment.
onAuthorize: function(data, actions) {
return actions.payment.get().then(function(paymentDetails) {
// Get at the payment details like this...
// paymentDetails.payer.payer_info.first_name;
// paymentDetails.payer.payer_info.shipping_address.city;
// paymentDetails.payer.payer_info.shipping_address.state;
var payload = {
paymentId: data.paymentID,
payerId: data.payerID
};
return paypal.request(
{
method: 'post',
url: '/your-api/execute-payment',
json: payload {
paymentId: data.paymentID,
payerId: data.payerID
}
}
).then(
function(res) {
// Gotten paid! Show confirmation page.
}
).catch(
function(err) {
// Dang it.
}
);
});
}
Your server receives the payment id and payer id from the client and makes another request to PayPal, this time to execute the payment. The transaction is complete if the execute request returns successfully. And now you can persist (or update) the payment data on your server.
// HTTP request data for executing a payment.
{
method: 'post',
// Remove '.sandbox' below to use production endpoint.
url: 'https://api.sandbox.paypal.com/v1/payments/payment/' + paymentId + '/execute/',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + 'your access token here'
},
data: {
payer_id: payerId
}
}
The client's latest request to your server completes successfully and you show a confirmation page, optionally with payment info from step 7 or from your server.
As for a place to start, here's what I suggest:
Automate requesting and storing your access token on your server. You'll need to store it because PayPal rate-limits token requests. So, either automate keeping it fresh or request a new one whenever you need to. I believe they expire in eight or nine hours; in any case, the expires-in time is given to you with the token. https://developer.paypal.com/docs/api/overview/
Build the /your-api/create-payment server endpoint. Test it with requests from an API tool like Postman using your access token. When everything goes well your server will make a successfull call to PayPal to create a payment, and you can explore the data in the response. It doesn't matter that you don't plan to execute the payment...it's the sandbox after all. Then build in your server-side persistence (if you want) and return the payment id to the client.
Next, load the PayPal script and your checkout-button rendering script on your site, and see if the Express Checkout login appears when you click the checkout button. If an error occurs in the create-payment process you'll see an error rather than the Express Checkout login.
When your system is creating payments and you can log in at the Express Checkout dialog with your sandbox credentials, build the /your-api/execute-payment endpoint. When your server has a working execute-payment endpoint you should be able to log in with Express Checkout and use your sandbox buyer account to complete a payment.
If after all that you think you'll have a go, the docs you want to pay attention to are https://developer.paypal.com/docs/api/ > API Reference > Payments API > Payments. There are five sections: create, execute, show, update and list. Read them. It will help.

Invalid transaction with Express Checkout REST API Paypal

I want to set up Paypal on my website but I have an issue with the Express Checkout, I followed this integration but I have an error after the initiation of the payment. Here is how I define my button
paypal.Button.render({
env: 'sandbox', // Specify 'sandbox' for the test environment
locale: 'fr_FR',
style: {
size: 'responsive',
color: 'blue',
shape: 'rect'
},
payment: function(resolve, reject) {
var CREATE_PAYMENT_URL = '/PayPalCreatePayment.php';
paypal.request.post(CREATE_PAYMENT_URL, {'commande': angular.toJson(commande)})
.then(function(data){
resolve(data.paymentID);
})
.catch(function(err){
reject(err);
});
}, '#paypal-button');
When I click on the generated button, it opens a lightbox with a connexion button which should open the review of the purchase and a button to execute the payment but instead I have a new window with a message :
This transaction isn't valid, please redirect to the merchant website
I have no error code or other message. The payment code that I generate in the CREATE_PAYMENT_URL is valid
I've already search for this on google but I'm still stuck, how can I solve this ? Tell me if you need more explanation

Facebook graph api Friend Invitations

I have managed to send and retrieve data from facebook for invitatin using
FB.ui({
method: 'apprequests',
to: sendto,
message: 'Win Mega Prizes!',
title: 'Enter in this contest!'
},
function (response) {
if (response && response.request_ids) {
var requests = response.request_ids.join(',');
alert(requests);
window.location.href = "http://www.rmyserver/index.php?invitations="+requests+"&contest_id="+c_id+"&page_id="+page_id+"&user="+from+"&g_id="+g_id+"&sendto="+sendto+"&single=1";
} else {
alert('canceled');
}
PHP
foreach($requests as $request_id) {
// Get the request details using Graph API
echo $request_content = json_decode(file_get_contents("https://graph.facebook.com/$request_id?$app_token"), TRUE);
But i want to use single user app request , as per docs i need to use TO: filed but this doesnt work, request is sent as well i get invitation id but php code used above returns false.
Am i missing something
you can try direct url example given here https://developers.facebook.com/docs/reference/dialogs/requests/#frictionless_requests
that should work fine from php
This works for me:
FB.ui({
method:'apprequests',
message:'I want you to open up your heart a little.',
to:123456798,
// filters:['app_non_users'], // commented: let users send notifications to app users too, probably a good idea to make them revisit?
data:'' // send data what you would like to track, FB will send that back in the URL for us
// #todo send google campaign parameters
});
Moreover you are doing it wrong on PHP side, you would need to redirect the user to a URL where the invitation friend selector would be displayed. There is no way in my knowledge to directly send an invitation to users using PHP.

Categories