PAYMENT.CAPTURE.COMPLETED: How to get parent payment? - paypal

When getting an event PAYMENT.SALE.COMPLETED in a webhook, you can use this code to get more information about the payer:
$resource = $webhookEvent->getResource();
$Payment = \Paypal\Api\Payment::get($resource->parent_payment, $apiContext);
$Payer = $Payment->getPayer();
$Payerinfo = $Payer->getPayerInfo();
Now I updated to SDK V2, and get PAYMENT.CAPTURE.COMPLETED-events. How does this work here? It seems there is no $resource->parent_payment. I tried something like:
$request = new PayPalCheckoutSdk\Orders\OrdersGetRequest($resource->id);
But this only returns RESOURCE_NOT_FOUND.
How can I get the Payerinfo here?

The resource->id returned is a v2/payments id, not an Order ID.
v2/checkout/orders IDs are only used during payer approval, and have no accounting value.

Related

What are valid payment-method-tokens?

I'm trying to create a credit card and therefore I need to call paymentMethodNone(). According to the documentation I can
Use PaymentMethod.create() to create a payment method for an existing customer:
// It's not clear what A_PAYMENT_METHOD_TOKEN has to be
Result<PaymentMethodNonce> result = bt.paymentMethodNonce()
.create("A_PAYMENT_METHOD_TOKEN");
String nonceFromTheClient = result.getTarget().getNonce();
Customer customer = customerResult.getTarget();
PaymentMethodRequest paymentMethodRequest = new PaymentMethodRequest()
.customerId(customer.getId())
.paymentMethodNonce(nonceFromTheClient);
Result<? extends PaymentMethod> paymentMethodResult = bt.paymentMethod()
.create(paymentMethodRequest);
PaymentMethod paymentMethod = paymentMethodResult.getTarget();
However, no word about what valid tokens are in the documentation. Neither here nor here - or am I just blind?
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
You do not need a payment_method_token to create a PaymentMethod.
To create a credit card, you will need to create a PaymentMethod. First, retrieve the payment_method_nonce from the incoming request. Next, create the PaymentMethod using PaymentMethodRequest.
//payment_method_nonce will be a post parameter in the request
//set nonceFromTheClient to equal payment_method_nonce
PaymentMethodRequest paymentMethodRequest = new PaymentMethodRequest()
.customerId(customer.getId())
.paymentMethodNonce(nonceFromTheClient);
Result<? extends PaymentMethod> result = gateway.paymentMethod().create(request);

Paypal Invoicing API, SendInvoiceRequest returns invoice null error

I'm using the C# SDK for our implementation (Classic API).
I can create an invoice fine, but whenever I try to send an invoice the response comes back with an error "Invalid request parameter: invoice cannot be null".
var result = new SendInvoiceResult();
var service = new PayPal.Invoice.InvoiceService(PayPalConfig());
var envelopeRequest = new RequestEnvelope
{
errorLanguage = "en_US", detailLevel = DetailLevelCode.RETURNALL
};
var request = new SendInvoiceRequest ( envelopeRequest, invoiceId );
var response = service.SendInvoice(request);
If I use the CreateAndSendInvoice method instead then a similar thing happens - the invoice gets created (I can view the URLs and the invoice shows as in draft) but it never sends.
Does anyone know what I'm doing wrong here?

Paypal rest api - how to get the return transaction id after execute

I'm using the Paypal rest api and the sdk to build my shopping cart, after a payment is created (POST /v1/payments/payment) and executed (POST /v1/payments/payment/{paymentId}/execute), I'm trying to decode the returned Payment object to retrieve the transaction ID.
I've var_dump the return object and get sth like (just the partial return here..):
object(PayPal\Api\Payment)#137 (1) { ["_propMap":"PayPal\Common\PPModel":private]=> array(8) { ["id"]=> string(28) "PAY-2xxxxxxxxxxxxxxx" .... ["transactions"]=> array(1) ...["related_resources"]=> array(1)
transaction and related resources exist and when I try to get the object value inside:
$result = $payment->execute($paymentExecute, getApiContext());
echo $result->getTransactions()->getRelatedResources()->getSale()->getId();
It said:
Fatal error: Call to a member function getRelatedResources() on a non-object
Is that sth wrong with my syntax..? the transaction ID exist according to var_dump recoard...
You can use something like this:
$transactions = $payment->getTransactions();
$resources = $transactions[0]->getRelatedResources();
$sale = $resources[0]->getSale();
$saleID = $sale->getId();
related_resources in an array, not an object, so there's your problem.

AngularJS $resource creating new object instead of updating object

// Set up the $resource
$scope.Users = $resource("http://localhost/users/:id");
// Retrieve the user who has id=1
$scope.user = $scope.Users.get({ id : 1 }); // returns existing user
// Results
{"created_at":"2013-03-03T06:32:30Z","id":1,"name":"testing","updated_at":"2013-03-03T06:32:30Z"}
// Change this user's name
$scope.user.name = "New name";
// Attempt to save the change
$scope.user.$save();
// Results calls POST /users and not PUT /users/1
{"created_at":"2013-03-03T23:25:03Z","id":2,"name":"New name","updated_at":"2013-03-03T23:25:03Z"}
I would expect that this would result in a PUT to /users/1 with the changed attribute. But it's instead POST to /users and it creates a new user (with a new id along with the new name).
Is there something that I'm doing wrong?
AngularJS v1.0.5
you just need to tell the $resource, how he has to bind the route-parameter ":id" with the JSON Object:
$scope.Users = $resource("http://localhost/users/:id",{id:'#id'});
This should work,
regards
thanks for the answer. It worked in the end for me too.
As a side note, I was using .NET WEB API and my entity has an Id property (UPPER CASE "I").
The PUT and DELETE worked only after I used the following:
$scope.Users = $resource("http://localhost/users/:Id",{Id:'#Id'});
Hope it helps.

delayed chained payment

Can anyone tell me how to automatically execute a delayed payment (let's say it's 5 days after the primary receiver receive the payment) in a chained payment manner? The key is automatic execution, not having to manually approve and pay the secondary receiver. Please illuminate with some sample code.
I have used "actionType" => "PAY_PRIMARY" so that primary receiver get money.
But how can I code so that secondary receiver get money?
Check this answer for the solution. Basically you just need to execute an ExecutePayment operation with the payKey within 90 days to send the payment to the secondary party.
actionType is PAY_PPRIMARY
you then trigger this payment within 90 days.
Its delayed but not time-elapsed.
https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_AdaptivePayments.pdf
well may be its too late but it will help someone in future for sure.
As we integrated paypal delayed chained payment, you can set a primary account in which all the amount will go and you can also set secondary account in which account will be transfered once they approved by primary account holder.
string endpoint = Constants_Common.endpoint + "Pay";
NVPHelper NVPRequest = new NVPHelper();
NVPRequest[SampleNVPConstant.requestEnvelopeerrorLanguage] = "en_US";
//NVPRequest[SampleNVPConstant.Pay2.actionType] = "PAY";
//the above one is for simple adoptive payment payment
NVPRequest[SampleNVPConstant.Pay2.actionType] = "PAY_PRIMARY";
//the above one for deleayed chained payment
NVPRequest[SampleNVPConstant.Pay2.currencyCode] = "USD";
NVPRequest[SampleNVPConstant.Pay2.feesPayer] = "EACHRECEIVER";
NVPRequest[SampleNVPConstant.Pay2.memo] = "XXXXXXXX";
Now we have to set primary and secondary receivers:
//primary account
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveramount_0] = TotalAmount;
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveremail_0] = "XXXx.xxxxx.com";
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiverprimary_0] = "true";
//secondary accounts
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveramount_1] = (somemoney out of total amount);
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveremail_1] = "xxxxx.xxxx.com";
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiverprimary_1] = "false";
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveramount_2] = (somemoney out of total amount);
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiveremail_2] = x.x.com;
NVPRequest[SampleNVPConstant.Pay2.receiverListreceiverprimary_2] = "false";
Don't forget that you have to give a valid paypal account while using delayed chained payment.
Now you get your pay_key which you have to use to execute your payment whithin 90 days so that other secondary receivers get money.
Here is the working code:
String endpoint = Constants_Common.endpoint + "ExecutePayment";
NVPHelper NVPRequest = new NVPHelper();
//requestEnvelope.errorLanguage is common for all the request
NVPRequest[SampleNVPConstant.requestEnvelopeerrorLanguage] = "en_US";
NVPRequest[SampleNVPConstant.ExecutePayment.payKey] = "your pay key";
string strrequestforNvp = NVPRequest.Encode();
//calling Call method where actuall API call is made, NVP string, header value adne end point are passed as the input.
CallerServices_NVP CallerServices = new CallerServices_NVP();
string stresponsenvp = CallerServices.Call(strrequestforNvp, Constants_Common.headers(), endpoint);
//Response is send to Decoder method where it is decoded to readable hash table
NVPHelper decoder = new NVPHelper();
decoder.Decode(stresponsenvp);
if (decoder != null && decoder["responseEnvelope.ack"].Equals("Success") && decoder["paymentExecStatus"].Equals("COMPLETED"))
{
//do something
}
Hope it will help someone.