I'm trying to create a new charge via the Go API. I have a shipping address and a payment token. But the Go API doesn't seem to support sending the shipping address. The documentation indicates that it should support it but there isn't a direct mapping between the arguments described in the docs and the Go ChargeParams arguments and some are missing.
type ChargeParams struct {
Params
Amount uint64
Currency Currency
Customer, Token string
Desc, Statement, Email string
NoCapture bool
Fee uint64
Fraud FraudReport
Source *SourceParams
}
Is there some other way that I'm supposed to add the address that I'm missing?
I know nothing about Stripe's API but if you follow the fields of the struct, you find Charge ➜ Source ➜ Card ➜ Address1, Address2, City, State, Zip, Country. Is that what you are after?
Answer from Stripe support.
Thanks for writing in about this, I'm happy to help! Unfortunately our
go bindings don't support that parameter at the moment which is why
you couldn't find it in the source. The temporary solution would be to
create the POST request yourself when you need to send the shipping
details along with the charge.
I've forwarded this internally to make sure it gets addressed in the
future but unfortunately I don't have any timeline to share with you
at the moment. We are definitely open to a Pull Request from one of
our users so if that's something you'd feel comfortable building
yourself that would be awesome!
Here's how to use ChargeParams to include shipping infomation https://github.com/stripe/stripe-go/blob/master/charge/client_test.go
charge, err := New(&stripe.ChargeParams{
Amount: stripe.Int64(11700),
Currency: stripe.String(string(stripe.CurrencyUSD)),
Source: &stripe.SourceParams{Token: stripe.String("src_123")},
Shipping: &stripe.ShippingDetailsParams{
Address: &stripe.AddressParams{
Line1: stripe.String("line1"),
City: stripe.String("city"),
},
Carrier: stripe.String("carrier"),
Name: stripe.String("name"),
}
})
Related
I am building a donation page where I want the user to decide the amount and frequency of the donation for hisself.
I looked up in the Braintree documentation, and I couldn't find out if and how to pass the amount of the subscription.
I am asking now how can I override the amount of the subscription. I am using Cashier/Braintree.
Should I apply them in the add-ons?
Full disclosure, I work at Braintree. If you have any further questions, contact support
You can change the default price of a subscription by passing the price parameter in your Subscription.create() API request. This will override the default price set by the plan you've configured. As an example, your API request may look something similar to this if you wanted to change the price of a single subscription to $20:
$result = $gateway->subscription()->create([
'paymentMethodToken' => 'the_token',
'planId' => 'the_plan_id',
'price' => '20'
]);
I've found that it is much easier to manage the price of subscriptions by using this method, however, you may also find it easier to use add-ons instead. If you choose to use add-ons, you'll need to create each add-on in the Control Panel.
require 'braintree'
# set credentials
Braintree::Configuration.merchant_id = 'XXX'
Braintree::Configuration.public_key = 'YYY'
Braintree::Configuration.private_key = 'ZZZ'
Braintree::Configuration.environment = :sandbox
# see the raw messages going to and from the Braintree server
Braintree::Configuration.logger = Logger.new(STDERR)
Braintree::Configuration.logger.level = Logger::DEBUG
customer = Braintree::Customer.create!(first_name: 'John', last_name: 'Doe')
begin
address = Braintree::Address.create!(customer_id: customer.id, locality: 'London')
pmethod = Braintree::PaymentMethod.create(customer_id: customer.id, billing_address_id: address.id, payment_method_nonce: 'fake-valid-visa-nonce')
p pmethod
ensure
# always delete the Customer in order not to leave much rubbish
# behind the testing session
Braintree::Customer.delete(customer.id)
end
I create a Customer, than an Address for him. When I attempt to create a PaymentMethod, using a nonce representing a credit card, and provide a billing address (by means of an ID of the previously saved Address), the PaymentMethod is not saved and error result is returned. The p pmethod line prints
#<Braintree::ErrorResult params:{...} errors:<credit_card:[(91701) Cannot provide both a billing address and a billing address ID.]>>
The error message doesn't make sense, as I only provide billing address ID. I have also checked that the SDK doesn't e.g. forge an empty address and send it to the server together with the PaymentMethod data provided in my code.
Creating a PaymentMethod without billing address works, but I really want to specify one.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
Bottom-line: At this time, you cannot test the billing_address_id with a test nonce, but it will work with a nonce generated for the sandbox from a Drop-in or Custom Integration at the client side.
This is a limitation of the testing API itself. When you submit one of the test nonces, it pre-populates with data that is commonly required for various checks. One of those pre-populated fields is that of billing_address=>zip_code which you can see if you do a vanilla payment method create with the fake nonce you are using. billing_address can be overwritten with whatever test values you want, but you can't undo it or zero it out.
I'm creating a new customer in stripe using a token created in the user's browser. This is on parse.com's servers, for what it's worth. I would like to retain a few details on the card, such as last4, but the customer object shows no sources under sources.data. Any pointers on how to get this information? Thanks for your help.
return Stripe.Customers.create({
source: token,
email: email
}).then(function(rr) {
console.log(rr.sources);
[ process response...]
});
This is the output:
{"object":"list","total_count":1,"has_more":false,"url":"/v1/customers/cus_[removed]/sources","data":[{}]}
It's bit strange that you are creating a customer but getting the object of customers list (https://stripe.com/docs/api/node#list_customers).
If customer is created successfully at stripe than it should return the customer object. You can check in more details here: https://stripe.com/docs/api/node#create_customer
I suggest here that please check the customer creation code once again at your side.
I'm working on an iOS app that uses Stripe to process payments. We are moving from a system that uses two separate charges for initial purchase and tip to a system that uses a single charge that begins as a hold on the user's account and then is captured upon setting the tip. This was the system that Stripe recommended to us when we inquired how to work with a single charge but also validate that the card can handle a charge of the designated amount.
For our back end, we are using Parse.com to track our orders, and so we are using Stripe's integration with Parse.com's Cloud Code as our server. Our main issue is that Parse.com doesn't seem to outright support most of Stripe's functionality (i.e. capturing charges). After some searching, I found that http POST requests were the best option to interact with Stripe.js and actually capture charges. However, I haven't been able to get quite that far because Parse.com is giving me a Code 141 error (Received unknown parameter: captured) when I try to create a charge that is uncaptured. Parse.com's Stripe API suggests that you can set all parameters through their Stripe.Charges.create, but it won't accept captured as a valid parameter.
To abstract for anyone else with this issue, how can I create a charge that has the parameter captured set to false using Parse.com Stripe API?
I have posted some of my Cloud Code below that should define a method to create a charge that has not yet been captured. This method is what is giving me the error that captured is not a valid parameter.
/**
* Create Hold on Card
* Required:
* orderCostInCents -- in cents ex. $10.24 = 1024
* customer -- cus_11EXEXEXEXEXEX
* description -- order.objectId to link it with order item.
*/
Parse.Cloud.define("holdAccount", function(request, response) {
//response.success("Not Charged");
var Stripe = require("stripe");
Stripe.initialize(kStripePrivateKey);
Stripe.Charges.create({
amount : request.params.orderCostInCents,
currency : "usd",
customer : request.params.customer,
captured : false,
description : request.params.description
},{
success: function(httpResponse) {
console.log(httpResponse);
response.success(httpResponse);
},
error: function(httpResponse) {
console.log(httpResponse.message);
response.error("Failed to create charge");
}
});
});
I believe that I can structure an http (POST) request after creating the charge by following the guidelines set at https://www.parse.com/questions/stripe-payment-capture-method-not-available. This guide might be very helpful to anyone else with my issue!
Best, and thanks for your help!
Edit: I realized that I didn't post the version of Cloud Code that we are using. It is 1.2.19.
Well, after taking a break from my hours of staring at the screen, I certainly feel like a doofus! The parameter I was using was captured, where the correct parameter should be capture. I was able to fix my issue by simply removing the "d" from the parameter name while creating the charge.
Whoops! I would still be open to advice on http requests via comments, but I will test those on my own and post a separate thread if I run into issues there as that issue is tangential to this one and thus off-topic.
For everyone joining, the answer is that the above code works perfectly if you replace the parameter captured with capture
Edit: For anyone else that is interested, the follow-up to this question was about actually making the capture via http requests on Parse Cloud Code. The following method works after much searching and trial and error. The hardest part here was figuring out how to format the URL since this is my first foray into http requests. If you need to chain parameters, simply add "&{parameter-name}={parameter-value}"
//kStripePrivateKey is your stripe private key
//Must pass in chargeID = stripe charge id and
//orderCostInCents = capture amount in cents as parameters
var captureURL = "https://"+ kStripePrivateKey +
":#api.stripe.com/v1/charges/"+
request.params.chargeID+
"/capture?amount="+request.params.orderCostInCents;
Parse.Cloud.httpRequest({
url: captureURL,
method: 'POST',
success: function(httpResponse) {
// Handle any success actions here
response.success(httpResponse);
}, error: function(httpResponse) {
response.error(httpResponse);
}
});
I am using UPS API for address validation. I am very new to this API and have just started learning.
I want to validate an address based on only zipcode i.e. I don't want to suppy the State name. It is not working in Test Integration environment. Any help?
I want to validate address using only Street Address and Zipcode. I don't want to supply State & City name. Is that possible? So far not working.
If I provide both State & Zipcode it is working nice.
How committed are you to the UPS API? My experience is that if they don't have it in the API already, it won't happen soon. There are other APIs available that will let you verify an address based on only the address and the ZIP code. typically, it is not necessary to provide a city or state if you have the correct ZIP code. The minimum required for address validation is street address and zip code or street address and city/state. how many addresses to need to verify each month? If you don't need a whole lot, there are a number of free APIs available. National address server is one, SmartyStreets.com is another. (I work for SmartyStreets.com.)
If you provide blank values for PoliticalDivision1 and PoliticalDivision2 the result back should include the city and state. You must still provide a valid address.
In a C++ application the following XML input used in street level address validator UPS API. Please use appropriate licence number, user id and password.
<?xml version=\"1.0\"?>
<AccessRequest xml:lang=\"en-US\"><AccessLicenseNumber>{LicenceNo}</AccessLicenseNumber><UserId>{UserId}</UserId><Password>{Passwd}</Password></AccessRequest>
<?xml version=\"1.0\"?>
<AddressValidationRequest xml:lang=\"en-US\">
<Request><TransactionReference><CustomerContext>Your Test Case Summary Description</CustomerContext><XpciVersion>1.0</XpciVersion></TransactionReference><RequestAction>XAV</RequestAction><RequestOption>3</RequestOption>
</Request>
<AddressKeyFormat><AddressLine>608 E. Evergreen Rd</AddressLine><PoliticalDivision2>LEBANON</PoliticalDivision2> <PoliticalDivision1>PA</PoliticalDivision1><PostcodePrimaryLow>17042</PostcodePrimaryLow><CountryCode>US</CountryCode> </AddressKeyFormat>
</AddressValidationRequest>
and following output received.
<?xml version=\"1.0\"?>
<AddressValidationResponse>
<Response>
<TransactionReference><CustomerContext>Your Test Case Summary Description</CustomerContext> <XpciVersion>1.0</XpciVersion></TransactionReference> <ResponseStatusCode>1</ResponseStatusCode><ResponseStatusDescription>Success</ResponseStatusDescription>
</Response>
<ValidAddressIndicator/>
<AddressClassification><Code>1</Code><Description>Commercial</Description></AddressClassification>
<AddressKeyFormat><AddressClassification><Code>1</Code><Description>Commercial</Description></AddressClassification><AddressLine>608 E EVERGREEN RD</AddressLine><Region>LEBANON PA 17042-7925</Region><PoliticalDivision2>LEBANON</PoliticalDivision2><PoliticalDivision1>PA</PoliticalDivision1><PostcodePrimaryLow>17042</PostcodePrimaryLow><PostcodeExtendedLow>7925</PostcodeExtendedLow><CountryCode>US</CountryCode></AddressKeyFormat>
</AddressValidationResponse>
Another potential solution besides the UPS API is the Service Objects address validation web service. Full disclosure, I work for Service Objects, but the web service objectively fits your needs.
It can process addresses with just the address1 and zipcode fields. The web service can validate the information, append the city, state, zip+4, note any corrections/changes, and provide a Delivery Point Validation (DPV) code indicating the address's deliverability. Below is an example input and output showing the actual service response.
If you are interested in trying out the API a free trial key is available for testing. You want to get more information about the nitty gritty technical details check out the Developer Guide
Example Input:
Address1: 27 E Cota St Ste 500
Zipcode: 93101
{
"Addresses":[
{
"Address1":"27 E Cota St Ste 500",
"Address2":"",
"City":"Santa Barbara",
"State":"CA",
"Zip":"93101-7602",
"IsResidential":"false",
"DPV":"1",
"DPVDesc":"Yes, the input record is a valid mailing address",
"DPVNotes":"26,28,39",
"DPVNotesDesc":"The input address matched the ZIP+4 record,The input address matched the DPV record,Highrise apartment\/office building address",
"Corrections":"10,23",
"CorrectionsDesc":"City change,State change",
"BarcodeDigits":"931017602254",
"CarrierRoute":"C006",
"CongressCode":"24",
"CountyCode":"083",
"CountyName":"Santa Barbara",
"FragmentHouse":"27",
"FragmentPreDir":"E",
"FragmentStreet":"Cota",
"FragmentSuffix":"St",
"FragmentPostDir":"",
"FragmentUnit":"Ste",
"Fragment":"500",
"FragmentPMBPrefix":"",
"FragmentPMBNumber":""
}
],
"IsCASS":true
}