Is Braintree_Customer::create() returns credit card object on success - braintree

Is Braintree_Customer::create() returns credit card object in braintree on success?
It returns on failure in verification object.
I want to know the best practice to access credit card object if it's present in response in case of success and failure of Braintree_Customer::create().

Seems like you can access the newly created customer's payment method within the successful result object (Python);
My customer create call:
result = braintree.Customer.create({
'first_name': 'John',
'last_name': 'Smith',
'company': 'Internet',
'email': 'john#example.com',
'payment_method_nonce':'fake-valid-nonce'
})
so
result.customer.payment_methods
will return an array containing the newly created payment method at index 0, which is essentially Braintree's Credit Card Result object, which contains all of the appropriate attributes for that credit card object.

Related

Using a single payment method ID between multiple customers in Stripe - Laravel Cashier

I have an application with two subscriber levels (company and reader). Person A has already subscribed as a company. He wants to Add person B as a reader subscriber.
Is there a way I can use the same payment method id Person A used in Stripe for the company to subscribe the Person B as a reader? When I try this, I get an error.
The payment method you provided has already been attached to a
customer.
Sample code
$user = User::where('id', 26)->first();
$user->subscription('company')->incrementQuantity(1);
$paymethod = $user->defaultPaymentMethod();
$id = 28;
$user2 = User::where('id', $id)->first();
$user2->newSubscription('reader', 'price_xxx')->create($paymethod->id);
A payment method can only be attached to a single customer. Either the subscription need to belong to the same customer also (and can then use the same payment method), or you'll need to collect the payment method again for a separate customer.

Stripe Subscription:Customer Creation

I am working on stripe subscription integration in my Spring Boot application. I am able to successfully redirect user to the checkout page and process the payment. I am working on the no-code application and the business model of my app is to charge the customer for each project created. Each time the user process the payment I am saving the customer-id and subscription-id in the database of the project but in order to subscribe to the same customer for the next project I have to create a new customer in the Stripe account and then the same flow continues. So, is it possible to subscribe the same customer for a new project without creating the customer in the stripe account?
I don't see why not. You just need to pass the existing customer Id when creating a checkout session.
That's what I'm doing:
If a user doesn't have a stripe customer created, I create one and store the customer id against my internal user id (I also send the user id in the customer metadata to stripe, so it's easy to correlate them, as they may use different email addresses for payment).
If a customer already exists for the current user, I just use that one.
I'm using typescript, the concept is the same:
// uid is my internal user id
const customerId = getOrCreateCustomer(uid);
const newSession: StripeType.Checkout.SessionCreateParams = {
customer: customerId,
mode: 'subscription',
payment_method_types: ['card'],
customer_update: {
address: 'auto',
name: 'auto',
shipping: 'auto',
},
subscription_data: {
metadata: { uid }, // store uid in subscription metadata as well
},
line_items: [
{
price: priceId,
quantity: 1,
}
],
success_url: successUrl,
cancel_url: cancelUrl,
};

Braintree PAyment create customer and save payment method

I am trying to save the card information and create customer at same time. The client app creates a nonce and sends it to my server (nodejs) and I call:
gateway.customer.create({paymentMethodNonce: request.params.nonce})
The customer gets created and I get a customer ID, I save that in the db. But calling
gateway.customer.find(customer_id):`
returns:
Customer {
id: '697983269',
merchantId: 'yzkvrqy9qsctn69d',
firstName: null,
lastName: null,
company: null,
email: null,
phone: null,
fax: null,
website: null,
createdAt: '2017-09-25T00:37:29Z',
updatedAt: '2017-09-25T00:37:29Z',
customFields: '',
creditCards: [],
addresses: [],
paymentMethods: [] }
Which has empty payment method array. I am using the drop in UI that only asks for card number and exp date. This is also a sandbox account.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact
support.
Hi Mehdi. I took a closer look at your Braintree Sandbox, and while you are in fact creating customer records in your Vault, it appears that there is no nonce value being passed into the customer creation API call, resulting in a customer record containing only a customer ID.
Would you mind logging, and relaying here, the value you get on your server for your request.params.nonce and ensure it contains a valid nonce string from your client?
Don't hesitate to reach out to support if you need further clarity.

Send 2 different types of mails using mailchimp

I have a set of internal users for my project. Admin can activate/deactivate them. I want to send them a mail saying "your account has been deactivated" when their account is deactivated by admin. Similarly they should receive a mail saying "your account has been activated" when admin activates their account. How can I do this?
I am trying by creating 2 separate lists in mailchimp and two separate campaigns. but when I'm writing mailchimps credentials in my development.js with 2 separate list ids and then trying to get it in my javascript file,it is getting undefined (checked by console.log)..
Is there a way to do it by just single campaign/list?
Here's my development.js code of mailchimp credentials:
mailchimp: {
api_key: "***************-***",
list_id1: "*********", //internal users
list_id2: "*********" //internal deactivated users
},
my user.helper.js
const config = require('../../config/environment');
const Mailchimp = require('mailchimp-api-3');
const mailchimp = new Mailchimp(config.mailchimp.api_key);
exports.addToDeactivatedList = function (email, name) {
console.log(mailchimp.list_id1);
mailchimp.members.create(config.mailchimp.list_id1, {
email_address: email,
merge_fields: {
FNAME: name
},
status: 'subscribed'
}).then(user => { }).catch(e => {
console.log("deactivate list me add ho gya");
})
}
exports.addToActivatedList = function (email, name) {
console.log(mailchimp.list_id2);
mailchimp.members.create(config.mailchimp.list_id2, {
email_address: email,
merge_fields: {
FNAME: name
},
status: 'subscribed'
}).then(user => { }).catch(e => {
console.log("activate list me add ho gya");
})
}
and my user.controller.js (selective part only)
var helper = require('./user.helper');
.
.
if(req.body.status != user.status){
(req.body.status == "active") ? helper.addToActivatedList(user.email, user.name) : helper.addToDeactivatedList(user.email, user.name);
}
All the help will be appreciated. THANKS
I'd try to put everyone in the same list, and then create segments based on that list. After that, create a campaign based on that segment.
You could for instance create a custom list attribute that records wether or not an account is activated and create a segment based on that attribute. The campaign should then be based on that segment.
Perhaps also record the date an account has been activated or deactivated by the admin in another custom attribute and use that to check if a user already had an activation/deactivation mail.
MailChimp offers a feature for situations like this called automations. Automations allow you to send individual emails to subscribers when an event is triggered. So instead of creating separate campaigns every time a user is activated or deactivated, you can use just two automations and a single list.
Whether a user is active or not can be tracked with list merge fields. To do this, you'll need to add a new text merge field to your list. Let's name the field label 'Active'. Uncheck the 'Visible' checkbox so the user can't see it, and name your merge field something like 'ACTIVE'. You can use values like yes/no or true/false to identify the users by their active status.
Next, create your automations, one for activated users and one for deactivated users. You can set a trigger to send the email when a list field value is changed. So just make each of your two automations send the emails when the 'Active' list field values change to either 'yes' or 'no'.
Then all you need to do with the API is subscribe users to a single list whenever their accounts are activated or deactivated. Just make sure the new 'ACTIVE' merge field is set to 'yes' or 'no' when you do this, and any addresses already subscribed will be updated with the new value. So your mailchimp.members.create() would look something like this, based on the example from here:
mailchimp.members.create(<list_id>, {
email_address: <user_email>,
merge_fields: {
FNAME: name,
ACTIVE: 'yes' //Or 'no' if being used for deactivated users
},
status: 'subscribed'
})

How to get the payment transaction of a subscription just created through Recurly's Ruby API?

If a subscription is created with
recurly_subscription = Recurly::Subscription.create!( ... )
the corresponding invoice can be retrieved with
recurly_subscription.invoice
But how to retrieve the corresponding payment transaction?
try this:
s = Recurly::Subscription.first
s.invoice.transactions

Resources