Giter Site home page Giter Site logo

Comments (5)

prakash-gangadharan avatar prakash-gangadharan commented on July 28, 2024

Hi @theyuv, what is the webhook event you are listening to? can you help here with the sample payload which you are using.

from paypal-java-sdk.

theyuv avatar theyuv commented on July 28, 2024

Example Webhook Event:
PAYMENT.SALE.PENDING

Example payload:
{
  "id": "***",
  "create_time": "2015-05-11T21:45:15Z",
  "resource_type": "sale",
  "event_type": "PAYMENT.SALE.PENDING",
  "summary": "Payment pending for EUR 3.76 EUR",
  "resource": {
    "reason_code": "RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION",
    "parent_payment": "PAY-13V79659LS5126423KVISFPI",
    "update_time": "2015-05-11T21:44:29Z",
    "amount": {
      "total": "3.76",
      "currency": "EUR"
    },
    "payment_mode": "INSTANT_TRANSFER",
    "create_time": "2015-05-11T21:44:29Z",
    "protection_eligibility": "INELIGIBLE",
    "links": [
      {
        "href": "https://api.paypal.com/v1/payments/sale/11139561TK568332L",
        "rel": "self",
        "method": "GET"
      },
      {
        "href": "https://api.paypal.com/v1/payments/sale/11139561TK568332L/refund",
        "rel": "refund",
        "method": "POST"
      },
      {
        "href": "https://api.paypal.com/v1/payments/payment/PAY-13V79659LS5126423KVISFPI",
        "rel": "parent_payment",
        "method": "GET"
      }
    ],
    "id": "11139561TK568332L",
    "state": "pending"
  },
  "links": [
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/***",
      "rel": "self",
      "method": "GET",
      "encType": "application/json"
    },
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/***/resend",
      "rel": "resend",
      "method": "POST",
      "encType": "application/json"
    }
  ],
  "event_version": "1.0"
}

from paypal-java-sdk.

prakash-gangadharan avatar prakash-gangadharan commented on July 28, 2024

@theyuv, can you help us with the code snippet you are using?

from paypal-java-sdk.

theyuv avatar theyuv commented on July 28, 2024
JsonObject eventJson = 
                new JsonParser().parse(requestAsString).getAsJsonObject();
Event event = Event.get(apiContext, eventJson.get("id).getString());
Sale sale = (Sale) event.getResource();

Is this enough?
Again, my questions are:

  1. Do I need to parse the json in order to get the event id, so that I can call Event.get()?
  2. Why doesn't parsing the resource to a Sale Object work?

from paypal-java-sdk.

jeffcjohnson avatar jeffcjohnson commented on July 28, 2024

I am also trying to figure out how to extract the resource from the event and found this:
https://stackoverflow.com/a/34122115

I tested it and it worked:

This is Kotlin but same same:

fun parsePaypalWebhookEventJson(eventJson: String): Event {
	return gson.fromJson(eventJson, Event::class.java)
}

fun parsePaypalWebhookResource(event: Event): PayPalResource? {
	val resource = event.resource as LinkedTreeMap<*, *>
	return when (event.resourceType) {
		"Agreement" -> gson.fromJson(gson.toJson(resource), Agreement::class.java)
		// "Dispute" -> gson.fromJson(gson.toJson(resource), Dispute::class.java)
		else -> null
	}
}

I commented out the Dispute part because I couldn't find it in my class path and assumed I must have an old library but no, I'm using the latest 1.14.0 which is from 2017.

Is this an open source project run by volunteers or run by PayPal employees, the same PayPal worth $126B?

from paypal-java-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.