How to get a transaction id from a successful payment? - paypal

I'm using PHP and the REST Paypal APIs to make simple payments. I'm able to call the Pay API and make a successful payment.
However, I don't know how to get the transaction id. I need to store it in order to make a refund in the case the customer complains on something. By now I'm only able to get it from my email (I get an email about the payment including the transaction id). So I read the email, take the transaction id and pass it to the web app in order to make a refund. I'd like to get such transaction id via some REST API too.

Check This link.
FYI:
// ### Get Sale From Created Payment
// You can retrieve the sale Id from Related Resources for each transactions.
$transactions = $payment->getTransactions();
$relatedResources = $transactions[0]->getRelatedResources();
$sale = $relatedResources[0]->getSale();
$saleId = $sale->getId();
Use below code to know all the information:
$payment = Payment::get($paymentId, $apiContext);
$obj = json_decode($payment);
echo "<pre>";
print_r($obj);
echo "</pre>";

Solved using the PaymentDetails API:
https://developer.paypal.com/docs/classic/api/adaptive-payments/PaymentDetails_API_Operation/
I passed to PayKey to the function and it returned the transaction ID for that payment. The PayKey is returned by the Pay API when the payment is made.

Related

Check if a PaypalTransactionID is valid (express checkout)

I am using Express Checkout. The DoExpressCheckoutPayment method completes the payment and returns a TransactionID.
I am using this transactionID in a web service. Is there a way to check if a transactionID is valid or belongs to a completed payment?
Thanks.
If the call is successful and you get a transaction ID then that's a valid ID. Not sure why you would think it's not..?? You could also make a call to GetTransactionDetails using that transaction ID just to confirm you get data back.

Rest API: Obtaining Payment ID after redirect back to merchant site

This question is specific to paying with a PayPal account.
So, here's the basic workflow:
I initialize a payment and redirect the user to PayPal's authentication page.
The user logs in and authorizes payment and is redirected back to the merchant site.
The payment is executed by obtaining and passing the paymentId and the payerId along.
In step one, a payment id is returned before redirecting to PayPal's site for user authorization. In step three, I need the payment id from step one in order to successfully execute the payment. Is there a way to obtain the payment ID without storing it in a session? The *payer*Id is passed back as a URL parameter when redirecting back to the merchant site. There is also a token value passed along, but I'm not sure what that is used for. All I know is that it's not the paymentId that I'm looking for.
Any help would be greatly appreciated.
Currently it has to be either session or DB or in similar lines. We suggest you generate a unique id for the transaction and use that to map to your PaymentId that you received in the response.
A code might look like:
$approvalUrl = $payment->getApprovalLink();
if ( preg_match( '/token=(EC\-[A-Z0-9]+)/', $approvalUrl, $matches ) ) {
$token = $matches[1];
$_SESSION['PAYPAL_PAYMENT'][ $token ] = $payment->getId();
} else {
// Error message here
return false;
}

PayPal SOAP API Error 13606 When trying to call Refund API method with Payer ID and amount

When I try to call RefundTransaction API method usiong PayerID i get Error "13606 Feature Not Enabled. You are not enabled for this feature.".
What it does mean? Is there a way to enable it?
To reproduce you can go to https://devtools-paypal.com/apiexplorer/PayPalAPIs and try to execute RefundTransaction method with PayerID and Amount filled in.
Direct from PayPal Support:
TransactionID and PayerID are marked "conditional", but you couldn't set blank.
For example, A buyer purchased several items in different period , but if you call RefundTransaciton API only set PayerID,
PayPal couldn't judge in which transaction to refund, and also could not refund the amount about all of these items.
PayPal is not allowed this case happen.
So at least you have to set the transaction ID while calling the refund API.
So the solution is to always specify TransactionID.
Yes, their own API Documentation says:
"Either the transaction ID or the payer ID must be specified."
But apparently this is not the case.
If you don't log subscr_payment IPN calls, you can look up TransactionID from a PayerID by using the TransactionSearch API request. Put your PayerID in the ProfileID search field.

PayPal REST API not returning payment_info

I am using the REST API to authorize a PayPal transaction, and when it returns to confirm & execute the payment, I'd like to retrieve & display payer information such as name, address, phone, etc from their PayPal account for a checkout order confirmation page. (To avoid them having to type in all their billing/shipping address info, since this should be available from PayPal.)
Currently the return is only showing this for payer:
PayPal\Api\Payment Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[id] => PAY-2EC51985XH550123JKHG3C4Y
[create_time] => 2013-06-28T15:53:23Z
[update_time] => 2013-06-28T15:53:23Z
[state] => created
[intent] => sale
[payer] => PayPal\Api\Payer Object
(
[_propMap:PayPal\Common\PPModel:private] => Array
(
[payment_method] => paypal
)
)
[transactions] => Array
...
The documentation states:
payer_info object
This object is pre-filled by PayPal when the payment_method is paypal.
(see https://developer.paypal.com/webapps/developer/docs/api/#payerinfo-object)
Even after the payment is executed, I still receive no payer_info object from PayPal. I am wondering if PayPal is only returning the info I prepopulate before sending the user off to PayPal? e.g.:
$payer = new Payer();
$payer->setPayment_method('paypal');
Is there a way to retrieve the user's name/address/phone/etc (what I expected to be available from Payment::get($pay_id)->getPayer()->getPayerInfo()->getShipping_address()) using the REST API?
Or do I have to have the user duplicate their efforts and enter address information on my checkout page? I sure hope not, as this is one of the big advantages of using PayPal as a payment method.
I thought I would post an answer in case anyone else has this issue.
It does appear that the REST API fails to return the shipping information the majority of the time. Especially when using the GET /payments/payment endpoint. However I have seen it return shipping information from the POST /payments/payment/<PAYMENT_ID>/execute endpoint before.
Anyway, following the comments above it looks as if the OP ditched the REST API and went back to Express Checkout. Which is fair enough if you want to get the shipping data up front.
However, if you use the PayPal IPN in conjunction with the REST API it will provide the shipping and billing info on the callback. So you could collect the information at that point.
The only problem I see with doing this is that you can't confirm the address is correct with the user. PayPal however does show this information to the user as they make their way through payment and allows them to change it if necessary. So I believe it's safe to assume the data is accurate.

Paypal Express checkout - not getting billing agreement ID

I'm trying to test reference transaction with Paypal Expresscheckout billing agreement id. But I don't get the BAID at all.
Here are the calls I'm making:
STEP 1: setExpresschecout call:
Request
Endpoint URL: https://api-3t.sandbox.paypal.com/nvp
HTTP method: POST
------------------------------------------------------------
POST data:
USER=insert_merchant_user_name_here
&PWD=insert_merchant_password_here
&SIGNATURE=insert_merchant_signature_value_here
&METHOD=SetExpressCheckout
&VERSION=93
&PAYMENTACTION=SALE # type of payment
&AMT=19.95 # amount of transaction
&CURRENCYCODE=USD # currency of transaction
&RETURNURL=<return_url> # URL of your payment confirmation page
&CANCELURL= <cancel_url> # URL redirect if customer cancels payment
&L_BILLINGTYPE0=MerchantInitiatedBilling
-------------------
Response
----------------------
token=EC-7NH28597U8423791A
-----------------------
It's reirecting me to Paypal for login and after clicking on 'Agree and Pay' button, redirecting me back to my site with token and payerID. As I don't need to store the customer details, I'm skipping GetExpresschecout call and directly calling doExpressCheckoutPayment with token and PayedID.
STEP2 : doExpresschecoutpayment
USER=insert_merchant_user_name_here
&PWD=insert_merchant_password_here
&SIGNATURE=insert_merchant_signature_value_here
&METHOD=DoExpressCheckoutPayment
&VERSION=93
&PAYMENTACTION=SALE # type of payment
&AMT=19.95 # amount of transaction
&CURRENCYCODE=USD # currency of transaction
&TOKEN=token_value
&PAYERID=payer_id_received
Here is the response. But it doesn't have the BILLING agreement id.
{"map":{"PAYMENTINFO_0_REASONCODE":"None","PAYMENTINFO_0_TAXAMT":"0.00","PAYMENTINFO_0_SECUREMERCHANTACCOUNTID":"KLQ6JKXB6DPZ6","TRANSACTIONID":"96C270379E2177052","PAYMENTINFO_0_TRANSACTIONTYPE":"expresscheckout","AMT":"11.20","PAYMENTINFO_0_FEEAMT":"0.62","CORRELATIONID":"fa14c423b7813","SUCCESSPAGEREDIRECTREQUESTED":"false","TAXAMT":"0.00","PAYMENTINFO_0_CURRENCYCODE":"USD","PAYMENTINFO_0_TRANSACTIONID":"96C270379E2177052","PENDINGREASON":"None","PAYMENTINFO_0_PAYMENTTYPE":"instant","VERSION":"98.0","PAYMENTINFO_0_PENDINGREASON":"None","FEEAMT":"0.62","ACK":"Success","TRANSACTIONTYPE":"expresscheckout","TOKEN":"EC-7NH28597U8423791A","PAYMENTINFO_0_ERRORCODE":"0","BUILD":"5956203","PAYMENTINFO_0_ORDERTIME":"2013-05-12T12:55:48Z","PAYMENTINFO_0_PROTECTIONELIGIBILITY":"Eligible","INSURANCEOPTIONSELECTED":"false","ORDERTIME":"2013-05-12T12:55:48Z","PAYMENTSTATUS":"Completed","PAYMENTINFO_0_AMT":"11.20","PAYMENTINFO_0_PAYMENTSTATUS":"Completed","REASONCODE":"None","PAYMENTTYPE":"instant","PAYMENTINFO_0_ACK":"Success","PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE":"ItemNotReceivedEligible,UnauthorizedPaymentEligible","SHIPPINGOPTIONISDEFAULT":"false","TIMESTAMP":"2013-05-12T12:55:48Z","PROTECTIONELIGIBILITY":"Eligible","CURRENCYCODE":"USD"}}
FYI..paymentaction is set to SALE as I need to capture the payment.
Any suggestions on what went wrong?
Thanks,
Punya
You will need to run CreateBillingAgreement API to get BAID.
This should be done after you get EC token from SetExpressCheckout API.
P.S Reference Transaction should be enabled on your account.
You will need to use "GetExpressCheckout" to see if they accepted the billing agreement or not.
You will also need to contact PayPal and specifically request that Billing Agreements and subsequently Reference Transactions are turned on for your merchant account.