No attached payment source for Stripe subscription creation - java

I'm currently migrating my app from using the Stripe Charges API to use the Stripe PaymentIntents API, in order to comply with SCA regulations.
My subscription creation code roughly looks like this:
Map<String, Object> srchOpts = new HashMap<>();
srchOpts.put("email", userEmail);
List<Customer> matchingCustomers = Customer.list(srchOpts).getData();
Customer customer = null;
Subscription subscription = null;
if ( matchingCustomers.isEmpty() ){
Map<String, Object> params = new HashMap<String, Object>();
params.put("email", userEmail);
params.put("payment_token", stripeToken);
customer = Customer.create(params);
}
else if (matchingCustomers.size() == 1) {
customer = matchingCustomers.get(0);
Map<String, Object> params = new HashMap<String, Object>();
params.put("source", stripeToken);
PaymentSourceCollection paymentSources = customer.getSources();
paymentSources.create(params);
}
Map<String, Object> item = new HashMap<String, Object>();
item.put("plan", planId); // e.g. my-pro-plan (no trial days)
Map<String, Object> items = new HashMap<String, Object>();
items.put("0", item);
Map<String, Object> params = new HashMap<String, Object>();
params.put("items", items);
params.put("customer", customer.getId());
params.put("off_session", false);
subscription = Subscription.create(params);
I can see on the Stripe dashboard (in test mode) that the customer is created and has the card which I specified, but the Subscription.create call fails with:
com.stripe.exception.InvalidRequestException: This customer has no attached payment source; code: resource_missing
The customer has a card set (there is only 1 so it has to be the default card), the customer creation call happens before the subscription creation call and the customer ID is being passed to the sub creation call. Is there some other parameter I need to pass in?
I've tried setting Customer.invoice_settings.default_payment_method when the customer is being created, and that gets me past the subscription creation. Everything looks fine from the Stripe dashboard, except that I'm testing with an SCA test card, so the transaction is incomplete until the customer has authenticated further.
I need the client secret token from the response to continue, and I thought that I would get it from #Subscription.getLatestInvoiceObject().getPaymentIntentObject().getClientSecret() but the getLatestInvoiceObject() call is returning null.
I'm not setting collection_method on the Subscription object which defaults to charge_automatically. This is what I want because the customer is on-session and so the Invoice being null probably makes sense, but how do I get the client secret to pass back to the frontend? The SetupIntent object returned by the subscription response exposes a client secret, but that object is null too.

Subscription Invoices will use whichever of these three payment options are available (in order of preference):
The Subscription's default_payment_method (reference) or default_source (reference)
The Customer's invoice_settings.default_payment_method (reference)
The Customer's default_source (note: there is no concept of a default PaymentMethod on Customers)
Also worth noting is that PaymentMethods and Sources are two distinct resources. Cards (objects with ids prefixed with card_) can be used as either type.

Related

How can i put data outside of child in firebase, i having problem look like this

i having an code look like this for uploading data inside realtime firebase
this is the realtime database look like i use code at below:
reference.child("Pending").child(currentDateandTime).child("DataKerja").setValue(tempatKerja);
reference.child("Pending").child(currentDateandTime).child("Alamat").setValue(alamat);
reference.child("Pending").child(currentDateandTime).child("AlamatKtp").setValue(alamatKtp);
reference.child("Pending").child(currentDateandTime).child("Nokontak1").setValue(noKontak1);
reference.child("Pending").child(currentDateandTime).child("Nokontak2").setValue(noKontak2);
reference.child("Pending").child(currentDateandTime).child("KTP").setValue(imageKTP);
reference.child("Pending").child(currentDateandTime).child("Pendukung").setValue(image2);
reference.child("Pending").child(currentDateandTime).child("DataPendukung").setValue (dataNasabah);
and i want to remove upload 1 data outside of the child that look like this
So the last .child("DataPelanggan")is gone
and when i try to remove that into this
reference.child("Pending").child(currentDateandTime).child("DataKerja").setValue(tempatKerja);
reference.child("Pending").child(currentDateandTime).child("Alamat").setValue(alamat);
reference.child("Pending").child(currentDateandTime).child("AlamatKtp").setValue(alamatKtp);
reference.child("Pending").child(currentDateandTime).child("Nokontak1").setValue(noKontak1);
reference.child("Pending").child(currentDateandTime).child("Nokontak2").setValue(noKontak2);
reference.child("Pending").child(currentDateandTime).child("KTP").setValue(imageKTP);
reference.child("Pending").child(currentDateandTime).child("Pendukung").setValue(image2);
reference.child("Pending").child(currentDateandTime).setValue (dataNasabah);
all the other file was gone and become this in below
so how can i solve it?
Your code did exactly what you programmed it for. To replace the child currentDateandTime's data with the new one dataNasabah.
Now, to keep the previous records and update/add new field, you use updateChildren() which prevents overwriting the previous data.
To use it, you pass a HashMap containing the value/fields you want to add without affecting other children of the node.
Sample code snippet from Firebase docs:
private void writeNewPost(String userId, String username, String title, String body) {
// Create new post at /user-posts/$userid/$postid and at
// /posts/$postid simultaneously
String key = mDatabase.child("posts").push().getKey();
Post post = new Post(userId, username, title, body);
Map<String, Object> postValues = post.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("/posts/" + key, postValues);
childUpdates.put("/user-posts/" + userId + "/" + key, postValues);
mDatabase.updateChildren(childUpdates);
}
Although, this code is an example for updating multiple child nodes of the database, simultaneously, which is why it's passing the child paths as string in the put(). But, for your use, you can change it to:
Map<String, Object> postValues = post.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put(currentDateandTime, postValues);
reference.child("Pending").updateChildren(childUpdates);

Android-Stripe add missing parameters while account creating

I was trying to implemented stripe payment gateway. Every thing is going fine. I was able to create connected account for the user in my stripe dashboard, but the problem is I'm missing following parameter
Website
SSN
Industry
Now I want to know how to add these parameters while creating account.
I have add the screen shot from stripe dashboard and here is the code:
Map<String, Object> dob =
new HashMap<>();
dob.put("day", "12");
dob.put("month", "1");
dob.put("year", "1991");
Map<String, Object> address =
new HashMap<>();
Map<String, Object> address_pram =
new HashMap<>();
address_pram.put("city", "Baton Rouge");
address_pram.put("line1", "1 Calais Ave");
address_pram.put("postal_code", "70806");
address_pram.put("state", "Louisiana");
address.put("address", address_pram);
address.put("dob", dob);
address.put("email", "ahmad#example.com");
address.put("first_name", "ahmad");
address.put("last_name", "bajwa");
address.put("phone", "+12015551023");
//address.put("website", "www.goldenkeystone.com");
//address.put("industry", "");
// address.put("ssn", "000000000");
Map<String, Object> acceptance =
new HashMap<>();
acceptance.put("date", System.currentTimeMillis() / 1000L);
acceptance.put("ip", ipString);
Map<String, Object> cardPayments =
new HashMap<>();
cardPayments.put("requested", true);
Map<String, Object> transfers = new HashMap<>();
transfers.put("requested", true);
Map<String, Object> capabilities =
new HashMap<>();
capabilities.put("card_payments", cardPayments);
capabilities.put("transfers", transfers);
Map<String, Object> params = new HashMap<>();
params.put("type", "custom");
params.put("country", "US");
params.put("tos_acceptance", acceptance);
params.put("business_type", "individual");
params.put("individual", address);
params.put("capabilities", capabilities);
Account account = Account.create(params, requestOptions);
Note: If still question is unclear, I would be glad if you add your contribution.
That data and other sensitive information would be collected by Stripe during the onboarding via Account Links: stripe.com/docs/connect/connect-onboarding
It's not something that you can pass to the Accounts API. See here for more information: https://stripe.com/docs/connect/collect-then-transfer-guide?platform=web#create-an-account-link

Amazon dynamo db java client - NoSuchMethodError

Trying to run a local amazon dynamo db client with the following code which is basically just a sample i have gotten online, I have created the table with local stack so it should exist not really sure what the issue is.
public static void main(String[] args) {
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable("attestation-db");
// Build a list of related items
List<Number> relatedItems = new ArrayList<Number>();
relatedItems.add(341);
relatedItems.add(472);
relatedItems.add(649);
//Build a map of product pictures
Map<String, String> pictures = new HashMap<String, String>();
pictures.put("FrontView", "http://example.com/products/123_front.jpg");
pictures.put("RearView", "http://example.com/products/123_rear.jpg");
pictures.put("SideView", "http://example.com/products/123_left_side.jpg");
//Build a map of product reviews
Map<String, List<String>> reviews = new HashMap<String, List<String>>();
List<String> fiveStarReviews = new ArrayList<String>();
fiveStarReviews.add("Excellent! Can't recommend it highly enough! Buy it!");
fiveStarReviews.add("Do yourself a favor and buy this");
reviews.put("FiveStar", fiveStarReviews);
List<String> oneStarReviews = new ArrayList<String>();
oneStarReviews.add("Terrible product! Do not buy this.");
reviews.put("OneStar", oneStarReviews);
// Build the item
Item item = new Item()
.withPrimaryKey("Id", 123)
.withString("Title", "Bicycle 123")
.withString("Description", "123 description")
.withString("BicycleType", "Hybrid")
.withString("Brand", "Brand-Company C")
.withNumber("Price", 500)
.withStringSet("Color", new HashSet<String>(Arrays.asList("Red", "Black")))
.withString("ProductCategory", "Bicycle")
.withBoolean("InStock", true)
.withNull("QuantityOnHand")
.withList("RelatedItems", relatedItems)
.withMap("Pictures", pictures)
.withMap("Reviews", reviews);
// Write the item to the table
PutItemOutcome outcome = table.putItem(item);
but i keep getting the following error when i run the main method.
Exception in thread "main" java.lang.NoSuchMethodError: com.amazonaws.util.StringUtils.trim(Ljava/lang/String;)Ljava/lang/String;
at com.amazonaws.auth.profile.internal.AwsProfileNameLoader.getEnvProfileName(AwsProfileNameLoader.java:72)
at com.amazonaws.auth.profile.internal.AwsProfileNameLoader.loadProfileName(AwsProfileNameLoader.java:54)
at com.amazonaws.regions.AwsProfileRegionProvider.<init>(AwsProfileRegionProvider.java:40)
at com.amazonaws.regions.DefaultAwsRegionProviderChain.<init>(DefaultAwsRegionProviderChain.java:23)
at com.amazonaws.client.builder.AwsClientBuilder.<clinit>(AwsClientBuilder.java:58)
at com.lmig.global.event.framework.sample.publisher.application.code.Attestation.main(Attestation.java:18)
It seems there are many versions of SDK present in classpath. can you try print the locations where classes are being loaded.
System.out.println(StringUtils.getClass().getProtectionDomain().getCodeSource());
System.out.println(AwsProfileNameLoader.getClass().getProtectionDomain().getCodeSource());

Update some data in firebase and leave unchanged other ones in the same "parent"

I'm making an app on android with firebase and I got stuck :(. I want to update some data in firebase and leave unchanged other ones in the same "parent". But when I use ref.updateChildren() function I am losing unchanged data :(. Like here:
Start data (before change) - The data that I don't want to change is marked blue
Data when the editor activity is finished:
My code in EditorActivity :
[...]
mEvent.setPlace(placeString);
mEvent.setDate(dateString);
mEvent.setType(mType);
mEvent.setWindPower(wind_power);
mEvent.setWaveSize(wave_size);
mEvent.setConditions(mConditions);
mEvent.setComment(commentString);
Map<String, Object> eventValues = mEvent.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put("/"+mEvent.getId(),eventValues);
mEventsDatabaseReference.updateChildren(childUpdates); [...]
On the Event.class :
#Exclude
public Map<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<>();
result.put("id", mId);
result.put("mUsername", mUsername);
result.put("place", mPlace);
result.put("date", mDate);
result.put("windPower", mWindPower);
result.put("waveSize", mWaveSize);
result.put("type",mType);
result.put("comment",mComment);
result.put("conditions",mConditions);
result.put("photoUrl",mPhotoUrl);
return result;
}
I know that I don't have "mMembers" in "result " and "mEvent" but I want to leave them unchanged in firebase database like on updateChildrenAsync() function from "Admin firebase". Is it possible?
My friend has sent me a code that solves my problem, it may be useful to someone in the future:
In EditorActivity:
mEvent.setPlace(placeString);
mEvent.setDate(dateString);
mEvent.setType(mType);
mEvent.setWindPower(wind_power);
mEvent.setWaveSize(wave_size);
mEvent.setConditions(mConditions);
mEvent.setComment(commentString);
Map<String, Object> eventValues = mEvent.toMap();
mEventsDatabaseReference.child(mEvent.getId()).updateChildren(eventValues);

Iterating over PagedList result retrieved from the Facebook Graph API

Trying to retrieve all marketing accounts of a Facebook business account using the spring social framework for Facebook .
I want to know if there is any better way to it other than what i did below ?
Does what i did for paging the query result is the right way to do it ?
Is there another way to retrieve data from the Facebook Marketing API ?
I really appreciate any help you can provide.
public List<String> getListAdAccountsId(String businessAccountId) {
final List<String> accountsId = new ArrayList<String>();
final MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
queryParameters.add("fields", "account_id");
queryParameters.add("offset", "0");
PagedList<Map> pagedResultSubSet = facebook.fetchConnections(businessAccountId, "adaccounts", Map.class,
queryParameters);
do {
queryParameters.set("offset", pagedResultSubSet.getNextPage().getOffset().toString());
pagedResultSubSet = facebook.fetchConnections(businessAccountId, "adaccounts", Map.class, queryParameters);
accountsId.addAll(pagedResultSubSet.parallelStream().map(e -> e.get("id").toString())
.collect(Collectors.toList()));
} while (pagedResultSubSet.getNextPage() != null);
return accountsId;
}

Categories

Resources