Sinan Ünal
Sinan Ünal

Reputation: 43

Implementation of paypal within App

I´m very new to the Integration of Paypal within an App so I have several questions. (I have just to implement the serversided scripts with PHP ...)

Do I understand the payment process right?:

  1. The app makes a payment and sends a proof of payment to the server.
  2. The Server looks up this payment and if everything is ok, the order is processed.

My Questions:

I. The compamy programing the app told me that I´ll get a payment_id to look up the payment details, then I´ll have to "capture" the payment and then process the order. What does "capture" mean?? If I recive a proof of payment, the payment is allready done, so what should I have to capture??

II. I try to get payment details with following script, but I only recive an Error:

$curl = curl_init("https://api.sandbox.paypal.com/v1/payments/payment/" . $payment_id);

curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
      'Authorization: Bearer ' . $api_key,
      'Accept: application/json',
      'Content-Type: application/json'
));

$response = curl_exec($curl);
$result = json_decode($response);
print_r($result);

the Error:

stdClass Object
(
    [name] => INTERNAL_SERVICE_ERROR
    [message] => An internal service error has occurred
    [information_link] => https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR
    [debug_id] => 950d09d5a33e1
)

III. Do I hav to authorize this proof of payment, or can I change it if there is any mistake?

Thanks in advance.

Upvotes: 1

Views: 93

Answers (1)

EdSF
EdSF

Reputation: 12341

The process for almost all types of online payment don't really differ much (implementation details may vary, but in the end):

  1. You request a payment service to process a payment for you
    • for credit card payments, typically this means requesting an Authorization to hold funds which you will need to Capture (finalize, complete, etc.) at some point. Some flows do this in one step (auth + capture), others are required to capture later (upon fulfillment of product/service).
  2. You will get a result to your request - re: your request: good or not (have funds or not, good account or not, etc)
    • Was authorization request good? Or not?
    • Was capture request good? Or not?

Paying with a Paypal account adds additional steps because you have to ask the user for access to their Paypal account/funding instruments. So that request goes through the same flow -

  • you request the user for "approval" (to access their Paypal account/funding instruments)
  • the user either approves or denies that request
  • if the user approves your request, same flow as above.

With all the above flows, you'll find data - e.g. payment_id, payer_id etc. that refer to items you need to complete the flow (you can infer what they are just by the names).

The most important part: You have to go through developer documentation and really understand all the details - for obvious reasons. Don't do things "piecemeal". These are flows that impact revenue for whomever you are doing this for. Paypal has SDKs with samples as well. Use them.

It's easy to code, but if you don't grasp what you're coding towards, it won't be pretty...

Upvotes: 1

Related Questions