How to access response from Paypal Express Checkout? - paypal

I am integrating PayPal Express Checkout as shown here.
https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/basic-integration/
I am processing the payment successfully, when the transaction has been authorized I am using actions.payment.get(); to get the information about the transaction.
This returns an object called SyncPromise with all the data I want to use.
console screenshot here
I have tried:
var response = actions.payment.get();
response.value
But I get undefined.
Does anyone how can I access the object element?

You need to call like so:
actions.payment.get().then(function(data) {
console.log(data);
});

Related

How should be the correct http request url in flutter to fetch data from the shopify store?

How should be the correct HTTP request URL in a flutter to fetch data from the Shopify store?
Any idea or material, how to integrate payment method with Shopify in a flutter when the user clicks the buy button?
I am trying with this line for HTTP requests, but not working
getUserData() async {
var response = await http.get(Uri.https(
'{apikey}:{password}#{hostname}.myshopify.com',
'/admin/api/{version}/{resource}.json'));
var jsonData = jsonDecode(response.body);
print(jsonData);
}
getUserData() async {
var response = await http.get(Uri.https(
'c948656b86f9a9e0bf8beffad653e484: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#verdenapp310.myshopify.com',
'/admin/api/2021-07/graphql.json'));
var jsonData = jsonDecode(response.body);
print(jsonData);
}
print output: I/flutter (31610): {errors: Not Found}
You are going to have to do some work. Study the architecture of the Shopify platform and then decide the correct API to use. In your brief example, you are choosing the Admin API, which is completely wrong for retrieving data from a store, unless you are an App installed in the store, to benefit the merchant experience. Usually, Admin API has nothing to do with customers.
Buy Button has a direct line to Shopify checkout. You do not get to install your own payment gateway through that button. The merchant has to select or install the payment gateway they want to use from their Shop. Note that it is possible to provide for custom payment gateways in Shopify but that is far outside the scope of your SO request here. Again, they have documentation for that too.

Pass additional parameter to paypal button url

I created a paypal button to manage my subscriptions and I´m planning to use it with my own link. Im not using the javascript SDK
Pay now
I was able to find that you can pass the &custom=123 parameter
but when I fetch a single subscription with
https://api-m.paypal.com/v1/billing/subscriptions/123
I don´t see the value of custom but I do see it in the POST request to my IPN endpoint. that means Paypal is sending it.
how can I see this custom value in the subscription itself? thank you!
Either: change to using a JavaScript SDK subscribe button and provide your value in the createSubscription's custom_id field
Or: continue using the legacy Subscribe button/link and try querying a v1/payments sale or v2/payments capture using a completed transaction ID for the subscription (not a profile ID), which might map to containing that legacy Subscribe transaction's custom value
Try this
<button onclick="pay()">Pay now</button>
<script>
function pay() {
$.ajax({
url: "https://www.paypal.com/cgi-bin/webscr",
type: "get",
data: {
cmd: _s-xclick,
hosted_button_id: 0000,
custom: 123
},
success: function(response) {
//Do Something
},
error: function(xhr) {
//Do Something to handle error
}
});
}
</script>

Meteor: Implement facebook package outside of accounts-facebook

I've got a Meteor application with a multi-phase sign-up process. The accounts are based on the accounts-password package. In the step prior to account creation, the user needs to provide some profile information.
I'd like the user to be able to launch a Facebook OAuth flow which pre-populates the profile fields with information pulled from Facebook.
This all needs to happen pre-account-creation. I want to implement this with the facebook package that backs accounts-facebook.
At the moment I've got the OAuth flow happening by calling Facebook.requestCredential, but I'm not sure how to get an OAuth access token from the credential token that comes back. I suspect I need to pass this to the server and make an API call to get back an access token.
Any pointers as to how this should work would be much appreciated.
Facebook.requestCredential(function (credentialTokenOrError) {
if (credentialTokenOrError && credentialTokenOrError instanceof Error) {
// Error...
console.log(credentialTokenOrError);
} else {
// Credential Token string
console.log(credentialTokenOrError);
// Now perhaps a Meteor.call to a server method that
// 1. Retrieves an access token
// 2. Hits the graph API to get profile information and returns it to the client
}
});
Thanks,
Chris
I was having the same trouble of converting a credentialToken to an accessToken, only with Github. I've written up a gist that has code that should work very similarly. Essentially, there are two steps:
Within your Facebook.requestCredential callback function, call OAuth._retrieveCredentialSecret(tokenOrError), the result of which is the credentialSecret. Then use Meteor.call, passing in tokenOrError and credentialSecret, to call the Meteor.method you'll set up in the next step.
code (on client):
Github.requestCredential({
loginStyle: 'popup',
requestPermissions: ['gist']
}, function(tokenOrError) {
if (tokenOrError && tokenOrError instanceof Error) {
// Throw a Meteor error
console.log('error getting the token');
return;
}
var credentialSecret = OAuth._retrieveCredentialSecret(tokenOrError);
Meteor.call('getGithubAccessToken', tokenOrError, credentialSecret, function(err, accessToken) {});
});
On the server, set up a Meteor.method that takes your credentialToken and credentialSecret and calls Facebook.retrieveCredential. This function returns a credentials object from the _pendingCredentials Mongo Collection before deleting it from the collection. The access token is credentials.serviceData.accessToken. The credentials object could potentially be persisted in the user object in the Meteor.users collection (as it is in the accounts packages) or sent back to the user.
code (on server):
Meteor.methods({
getGithubAccessToken: function(credentialToken, credentialSecret) {
var credentials = Github.retrieveCredential(credentialToken, credentialSecret);
console.log('accessToken:', credentials.serviceData.accessToken);
return credentials.serviceData.accessToken;
}
});
I'm unfamiliar with the specifics of Facebook's Graph API so after these steps, you're on your own. Good luck!

PAYPAL RESTful API execute call occasional error

I have fully integrated my website with paypal using paypal RESTful's API PHP SDK. Now my problem is every once in a while on the payment process, once the user approves the payment and it comes back to my website for execution, the API execution request comes back with the following responses from paypal. The HTTP response code's in these scenarios are 400 and 500. Below I have listed the error name and error message which comes as a part of the JSON response I get form paypal on execute action (https://api.paypal.com/v1/payments/payment/PAY-xxxxxxxxxxxxxxxxxxxxxxxxxx/execute):
400 PAYMENT_NOT_APPROVED_FOR_EXECUTION,Payer has not approved payment
500 INTERNAL_SERVICE_ERROR,An internal service error has occurred
In terms of the code I use to make that call I have added the function which executes the payment. I should add that this is working in 98% of times. Below is the code:
public function getExecute()
{
// Payment is cancelled
if (!(Input::get('success') && Input::get('success') == 'true'))
return $this->runPaymentExitProcess();
// No paymentId
if (!Session::has('paymentId'))
return "No payment id to execute";
$paymentId = Session::get('paymentId');
$this->payment = Payment::get($paymentId, $this->apiContext);
// The payer_id is added to the request query parameters when the user is redirected from paypal back to your site
$this->execution->setPayer_id(Input::get('PayerID'));
$response = $this->payment->execute($this->execution, $this->apiContext);
// Check for paypal errors
if (isset($response->name)) {
// When we have a paypal error
if ($this->hasPaypalError($response)) {
$error = array('name' => $response->name, 'message' => $response->message);
Session::put('error', $error);
return (MODE == 'LIVE') ? Redirect::to('/paypalerror') : Redirect::to('/paypalerror'.MODE_PARAM);
die;
}
}
// Unset session
Session::forget('paymentId');
// execution successful
if ($this->addPaymentIdToUser($paymentId))
return (MODE == 'LIVE') ? Redirect::to('/') : Redirect::to('/'.MODE_PARAM);
}
The code is in laravel. Please note that the $this->apiContext is set in the constructor of the class. Also this is the function is the success url which is set in the API under redirect_urls.
Can someone please help me figure out if this issue is coming from my side or Paypal's side?
For the 400 error, this would occur if the user decided not to approve the payment. If you think the payment was actually approved in the web flow then that would be an issue to look into further.
Can you provide the debugId and approximate time (with timezone, or GMT) of a 500 internal server error response, and a 400 if you believe the payment was actually approved by user.

How to get secure token when using "Hosted Checkout Pages" and RestApiSDK - ASP.Net

Is it possible to use the RestApiSDK to get a secure token when using "Hosted Checkout Pages"? If so please show example. (C# preferred.)
The secure token I am referring to is described on page 31 here:
https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/payflowgateway_guide.pdf
Please realize that I am not using "Express Checkout". (There is a lot of confusion between the old PayPal products and the new products in the PayPal documentation.)
One example I found here on StackOverflow has the following issues:
The links to the SDK and docs are dead.
The DOSecureTokenAuth.cs file does not exist in any SDK or example that I can find.
PayPal's Payflow Gateway SDK Example not working
In this example the author was not able to copy the code from the source files.
http://forums.asp.net/t/1798900.aspx/1
Thank you,
Chuck
https://github.com/paypal/rest-api-sdk-dotnet please look into this
or you can use
payflow_dotnet.dll
Please look into this code of payflow_dotnet.dll
public void CreateAuthorization()
{
// Create the Payflow Connection data object with the required connection details.
// The PAYFLOW_HOST property is defined in the webconfig
PayflowConnectionData Connection = new PayflowConnectionData();
// Create Invoice
Invoice Inv = new Invoice();
// Set Amount
Currency Amt = new Currency(new decimal(premiumAmount), "USD");
//adding the amount to invoice
Inv.Amt = Amt;
//creating a new express check out request
ExpressCheckoutRequest currRequest = new ECSetRequest(WebConfigkeys.ReturnToApplication, WebConfigkeys.ReturnToApplication);
PayPalTender currTender = new PayPalTender(currRequest);
//creating a new transaction
SaleTransaction currTransaction = new SaleTransaction(User, Connection, Inv, currTender, PayflowUtility.RequestId);
//submitting the transaction and accepting the response message
Response Resp = currTransaction.SubmitTransaction();
if (Resp != null)
{
TransactionResponse TrxnResponse = Resp.TransactionResponse;
ExpressCheckoutResponse eResponse = Resp.ExpressCheckoutSetResponse;
if ((TrxnResponse != null) && (eResponse != null))
{
eResponse.Token;//get your token
}
}
}
Add this to Web Config
<add key="PAYFLOW_HOST" value="pilot-payflowpro.paypal.com" />
It is not currentlypossible. The REST API's do not support the Hosted Checkout payment method. The REST process allows for PayPal transactions (very similar to Express Checkout) and credit card payments (where you pass the billing information to PayPal for verification).
The post you mentioned - PayPal's Payflow Gateway SDK Example not working - is for the Payflow SDK and Payflow does not support REST.