Ali Shaukat
Ali Shaukat

Reputation: 965

Paypal Payment Execution

I am creating a PayPal application using credit card. It is creating payment successfully with approved status.

$addr = new Address();
$addr->setLine1($street);
$addr->setCity($city);
$addr->setPostalCode(zip);
$addr->setState($state);
$addr->setCountryCode($code);

$card = new CreditCard();
$card->setNumber($number);
$card->setType($type);
$card->setExpireMonth($m);
$card->setExpireYear($y);
$card->setCvv2($cvv);
$card->setFirstName($fname);
$card->setLastName($lname);
$card->setBillingAddress($addr);

$fi = new FundingInstrument();
$fi->setCreditCard($card);

$payer = new Payer();
$payer->setPaymentMethod('credit_card');
$payer->setFundingInstruments(array($fi));

$amountDetails = new Details();
$amountDetails->setSubtotal('100');
$amountDetails->setTax('10');
$amountDetails->setShipping('10');

$amount = new Amount();
$amount->setCurrency('JPY');
$amount->setTotal('120');
$amount->setDetails($amountDetails);

$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription('This is the payment transaction description.');

$payment = new Payments();
$payment->setIntent('sale');
$payment->setPayer($payer);
$payment->setTransactions(array($transaction));

$payment->create($this->_api_context);

Now I am trying to execute this payment in order to complete the transaction but I am unable to find the payer id. What is this payer id and where do I get it from?

$payer_id = ?;
$paymentExecution = new PaymentExecution();
$paymentExecution->setPayerId($payer_id);
$payment->execute($paymentExecution, $this->_api_context);

Upvotes: 2

Views: 827

Answers (2)

Ali Shaukat
Ali Shaukat

Reputation: 965

The Credit card Payments are one step process where payment is made when $payment->create($this->_api_context); is approved.

So there is no need of execute step ($payment->execute($paymentExecution, $this->_api_context);). Also, we don't need payer id in this case.

Upvotes: 2

Şivā SankĂr
Şivā SankĂr

Reputation: 2036

You will get payer_id from return URL(GET Method) of "Create a payment". Check on Paypal REST API Reference for more details

Upvotes: 1

Related Questions