How to get customer billing address in blCheckoutWorkflow in broadleaf? - broadleaf-commerce

I would like to the get customer billing address details and would like to log them in an activity class in the blCheckoutWorkflow.
I have tried the following.
Order order=context.getOrder();
Customer c=order.getCustomer();
c.getCustomerPayments().get(0).getBillingAddress();
But here the size of the list returned by getCustomerPayments() is 0. So I am getting ArrayIndexOutOfBoundsException.
Is there a way to get the billing address that is entered by the customer in the /checkout.
Kindly, reply me.

getCustomerPayments() is designed to hold saved payment information for a particular Customer and is not really applicable to the current Order. This is used when a Customer wants to save payment information for checking out next time (the 'token' property on CustomerPaymentImpl is used to look up the PCI-sensitive data from the payment gateway).
If you are using Broadleaf 3.1.0-GA+ then you should do:
Order order = context.getOrder();
Address billingAddress = order.getOrderPayments().get(0).getBillingAddress();
If you are using Broadleaf 3.0.10-GA or below you should do:
Order order = context.getOrder();
Address billingAddress = order.getPaymentInfos().get(0).getAddress();

Related

How to get default payment method from Stripe invoice?

I am listening to Stripe's invoice.payment_failed webhook with my web app and I would like to get the default_payment_method from each invoice but for some reason it always returns nothing but an empty array!
When I query for a Stripe invoice on the command line and expand on the default_payment_method like this...
Stripe::Invoice.retrieve('in_3K6dIY2KgYRkshw2LAzya63P', :expand => "default_payment_method")
...I also get empty arrays. This surprises me because all my Stripe customers do have a default payment method associated with them.
What am I missing here?
Thanks for any help.
There are three independent places a default payment method can be set. From more specific to less specific they go :
invoice.default_payment_method (which you are looking at)
subscription.default_payment_method
customer.invoice_settings.default_payment_method
Stripe charges the most specific one if it's set. When reading from the API, those values don't inherit from the level above, they can all be set individually, if they are not set explicitly then they are null. So that's why you see it as null on the Invoice level.
Instead you likely want to look at the Subscription object or the Customer object(and can leverage the expand feature for that), depending on how you built your integration and which one it sets.
Overall though, you probably actually want the PaymentMethod used in the invoice payment though? That would be from the last_payment_error.
inv = Stripe::Invoice.retrieve({
id: 'in_1K8iiKJoUivz182DMzSkuBgp',
expand: ["customer.invoice_settings.default_payment_method",
"subscription.default_payment_method",
"payment_intent"]
}
)
print("invoice : #{inv.default_payment_method} \n")
print("subscription : #{inv.subscription.default_payment_method} \n")
print("customer : #{inv.customer.invoice_settings.default_payment_method} \n")
print("failed charge : #{inv.payment_intent.last_payment_error.payment_method} \n")

Get Default Payment Source (default card) for Stripe Customer?

I created a POC with a customer/credit card in Stripe and I logged into my dashboard within Stripe and was able to see this customer has a default source (the test credit card I added) associated correctly. It shows this card is the default source.
When I run this .Net code:
var customerService = new CustomerService();
var stripeCustomer = await customerService.GetAsync(customerId);
To get that customer, it returns everything correctly except his source. All of the fields I had hoped I can find it from are empty! I want to know his default payment source so I can show it on the front end with a little icon to indicate it's default.
DefaultSource, DefaultSourceId, and Sources properties are all blank/null.
Is there a way to have Stripe return it, or do I need to do something else? I tried the 'expand' property for the GetAsync method but that threw an error saying the above properties are not expandable (i.e. I can't ask Stripe to expand/return Source).
Any ideas what I can do?
FYI I also tried this:
var paymentMethodService = new PaymentMethodService();
var cards = await paymentMethodService.ListAsync(new PaymentMethodListOptions { Customer = customerId, Type = "card"});
and there doesn't seem to be a property anywhere that says the card is default (although it does correctly return all cards). I believe Stripe documentation states the Customer is the holder of the default source, not the card object. What gives?
Thanks in advance!
It looks like you're using Payment Methods, since your payment method list call has the results you expect, which means the customer likely doesn't have any sources. You can try that again with the properly pluralized expand[]=sources if you do know your Customer has Sources attached.
For Payment Methods, there is no general default for the Customer. For one-time Payment Intents, you must always specify the payment_method from among those attached to the Customer for future payments.
For paying invoices (related to recurring subscriptions, eg), you can set the invoice_settings.default_payment_method for Customer. This only applies to invoices.

Stripe: Get card information so customer can update their card

My app uses subscriptions with Stripe.
I want to create a standard "account" page, which will list the customer's current card information (like "MasterCard" and last 4 of card number), and give the customer the option of updating that information.
I'm stuck on the first piece--getting back the current card information. To do this, I need the current card_id. I have tried the "listSources" method, but this returns blank data where the card info is supposed to be. What do I need to do to get that card info?
Here is what I've tried:
(I'm using Node, and running this server side)
The closest method I have found is here:
var stripe = require('stripe')(STRIPE_TOKEN);
stripe.customers.listSources(
CUSTOMER_ID,
{object: 'bank_account', limit: 3},
function(err, cards) {
// asynchronously called
}
);
This returns information (there's no error), but the docs say this method should return a data array of the cards that includes the card id for each. In testing, the data array keeps coming back empty.
I am testing with a customer id that has a valid subscription and a card that I can see on my Stripe dashboard.
Why is the data array coming back empty?
Note: there's also a retrieve source method, which should give back card details, but this method requires you have the id of the card you want info on, and that's what I am not able to get right now.
Converting this to an answer...
Stripe has recently rolled out PaymentMethods, which replace (and are separate from) the older Tokens and Sources API.
OP's issue is that their integration creates PaymentMethod objects, which won't show up in the sources list, but can instead be accessed via stripe.paymentMethods.list.

Accessing Address fields in Suitescript on Transaction level

In 2014.2 Netsuite changed it's structure of addresses making them subrecords. They have a lot of help around scripting addresses on the Customer level or Form level, however I need to on the transaction (quote, sales order, invoice) level.
Help for transaction level appears to be just this page: https://netsuite.custhelp.com/app/answers/detail/a_id/39551/kw/address
This however is creating a custom address which shows that custom billing and shipping addresses have their own internal id.
What is the internal ID that I can use on the nlapiViewSubrecord(fldName) call to get at the values of say country, state, zip, etc on the billing and/or shipping addresses? I have tried 'billaddress' and 'shipaddress' respectively with no luck.
Try billingaddress and shippingaddress. I've recently made a similar update to some of our Sales Order code, and this is what worked for me.
// {String} The type of address to create, will be one of ship or bill
var addressType = (type === 'ship' ? 'shippingaddress' : 'billingaddress');
// {nlobjSubrecord} Address subrecord object
var subrecord = order.createSubrecord(addressType);
(This is in a RESTlet; the type value here is something that gets sent to us)

How to get list of payment methods/shipping method and assign it to a order (suitescript)

I'm working with creating salesorder in netsuite using suitescript but I can't find any document about "payment method", so how can I get a payment method such as VISA card and assign to the order? (I think it's required a payment method id but I didn't find payment method in supported suitescript records).
[update]
Here is my code:
var order = nlapiCreateRecord("salesorder");
// set some field value
// order.setFieldValue(....)
Now I want get payment method and shipping method id to set to order:
order.setFieldValue("shipmethod", shippingmethodId);
order.setFieldValue("paymentmethod", paymentmethodId);
I already have payment method name "Test Payment Method" and shipping method "Test Shipping Method". How can I get their id using their name?
For Payment Methods:
To get a list of the payment methods and their respective IDs available in your NetSuite account, you should navigate to Setup > Accounting > Accounting Lists. You will see a Type filter on the bottom of the page. Select Payment Method in there and you'll be able to see the different payment methods available for you.
For Shipping Methods:
Navigate to Lists > Accounting > Shipping Items.
Edit:
Actually you don't need to. Use nlobjRecord.setFieldText instead of setFieldValue i.e. order.setFieldText('VISA')
You can use hard-coded values instead of getting the values dynamically.

Resources