Last active
October 9, 2023 03:42
-
-
Save ricardo85x/ecfe48c8103dbb10ac7f78f107f92dd0 to your computer and use it in GitHub Desktop.
When using stripe-java to get the expanded total_details.breakdown from checkout session, some fields inside discount are missing like id and promotion_code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.ricardoteixeira; | |
import com.stripe.Stripe; | |
import com.stripe.model.checkout.Session; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
public class Main { | |
public static void main(String[] args) { | |
Stripe.apiKey = "sk_test_..."; | |
String session_id = "cs_test_..."; | |
List<String> expandList = new ArrayList<>(); | |
expandList.add("total_details.breakdown"); | |
Map<String, Object> params = new HashMap<>(); | |
params.put("expand", expandList); | |
try { | |
Session session = Session.retrieve(session_id, params, null); | |
System.out.println(session.getTotalDetails().getBreakdown()); | |
// response: | |
/* | |
{ | |
"discounts": [ | |
{ | |
"amount": 5000, | |
"discount": { // MISSING FIELDS LIKE promotion_code and id | |
"amount": null, | |
"discount": null, | |
} | |
} | |
], | |
"taxes": [] | |
} | |
*/ | |
} catch (com.stripe.exception.StripeException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment