A customer object can have many cards in Stripe.com. How do you charge an existing card?
I've tried a few things, but the stripe api for some reason borks when to get an old customer token and a new card token instead of just creating a new card on that customer. So I've gone the route of retrieving all the customer's cards, then selecting one by radio button, then submitting the token of the chosen card into a charge
charge = Stripe::Charge.create(
:amount => "#{#subscription.price}",
:currency => "usd",
:card => params[:existing_card_id],
:description => "Subscription for #{current_user.email}"
)
but I get the error
Stripe::InvalidRequestError: Invalid token id: card_24j3i2390s9df
I figured this out.
With existing card tokens you have to send in the customer token as well
charge = Stripe::Charge.create(
:amount => "#{#subscription.price}",
:currency => "usd",
:customer => current_user.stripe_customer_id,
:card => params[:existing_card_id],
:description => "Subscription for #{current_user.email}"
)
This answer help to ME apply the same solution in PHP for charge an specific credit card customer, other than the default credit card. Here the pieces:
JSON:
{
"charge": {
"amount":122,
"currency":"usd",
"customer":"cus_7hVsgytCc79BL7",
"card":"card_17SENFJ4sx1xVfmD8skoSjNs"
}
}
PHP
$item = $params->request->getJsonRawBody();
$new_charge = \Stripe\Charge::create(array(
"amount" => $this->ConvertAmount($item->charge->amount),
"currency" => $item->charge->currency,
"customer" => $item->charge->customer,
"card" => $item->charge->card
));
return $new_charge;
Related
I am creating the following pay request with the ruby adaptive payment sdk:
fee = 2
api = PayPal::SDK::AdaptivePayments.new
pay = api.build_pay({
:actionType => "PAY",
:cancelUrl => "https://localhost:3000/purchases/paypal_cancelled?purchase_guid=" + self.guid,
:currencyCode => self.currency,
:feesPayer => "PRIMARYRECEIVER",
:ipnNotificationUrl => "http://paypal.corstiaan.ultrahook.com/purchases/paypal_ipn_notify?purchase_guid=" + self.guid,
:receiverList => {
:receiver => [{
:amount => 20,
:email => seller#email.com,
:primary => true
}, {
:amount => fee,
:email => 'ch-facilitator#corstiaan.com'
}],
},
:returnUrl => "https://localhost:3000/purchases/paypal_success?purchase_guid=" + self.guid + "&verification_key=" + paypal_verification_key })
pay_response = api.pay(pay)
Everything works just like I want it to. I am the facilitator of the transaction and secondary receiver and the seller is the primary receiver. This is all ok. Also, the cancel and return urls are being called correctly.
Only the ipnNotificationUrl is not getting hit. I have set up a forward using ultrahook.com which is getting called correctly when using paypal's ipn simulator (that does not support adaptive ipn messages for some reason...) so technically that forward should work, but I never see anything hitting my server...
I am lost in the paypal docs, which are terrible.
When I view the IPN history ch-facilitator#corstiaan.com I only see IPN messages that relate to the payment of the fee from the seller to facilitator, nothing regarding the whole transaction which should be posted to ipnNotificationUrl if I understand correctly up to this point.
What am I doing wrong/what can be the problem? Thanks!
I am using PayPal adaptive payment. I want to send shipping address of sender to reciever.
I am doing following things
First I am getting the approval key from sender with Preapproval API
Then, i am using PAY Create API.
This are the paramters
:actionType => "CREATE",
cancelUrl: 'https://www.example.com/paypal_cancelurl',
returnUrl: 'https://www.example.com/paypal_successurl',
:currencyCode => "USD",
:preapprovalKey => preapproval_key,
:receiverList => {
:receiver => [{
:amount => total,
:email => reciever#example.com }] }
After getting paypal paykey from step 2, i am using Set Payment Option API . I am passing following information
:payKey => paykey,
:displayOptions => {
:businessName => "Example Site" },
:senderOptions => {
:shippingAddress => {
:addresseeName => sender_name
:street1 => sender_street,
:city => sender_city,
:state => sender_state,
:zip => sender_zip,
:country => "US"
}
}
Lastly, I am executing payment with Execute Pay API.
Everything is fine but when reciever review this payment in paypal screen, he don't see the shipping address which i sent to him. His paypal screen say that the sender has no shipping address.
I cross checked, fetched the Payment Details with Payment Details API, found that shipping address is there, strange?
What i am missing, why shipping address is not visible in paypal screen.?
Update: all above flow is done on sandbox.I'm not sure this matters but thought to mention it.
The shipping options would have to work in the embedded payment flow, your request payload looks fine, and you would just need to modify the redirection codes with JS lightbox or minibrowers, as per this instruction: How to Create an Embedded Payment Flow Using Adaptive Payments
I want to save a Stripe card_id to my database based on the JSON response. I'm playing with the examples from the Stripe documentation right now:
customer = Stripe::Customer.retrieve("cus_3Ek7h52yGbLpQo")
customer.cards.create(:card => {:number => "4242424242424242",
:exp_month => 10, :exp_year => 2014})
The JSON looks like this:
#<Stripe::Card:0x3ff2f0191540> JSON: {"id":"card_3GHjrJqMgoyTNy","object":"card","last4":"4242","type":"Visa","exp_month":10,"exp_year":2014,"fingerprint":"Ds0FdzrOSdYMkwC0","customer":"cus_3Ek7h52yGbLpQo","country":"US","name":null,"address_line1":null,"address_line2":null,"address_city":null,"address_state":null,"address_zip":null,"address_country":null,"cvc_check":null,"address_line1_check":null,"address_zip_check":null}
In my controller, after creating the credit card, how can I parse the JSON to get only the card id? Is it even possible?
You should be able to get the credit card from the response like this:
#card = customer.cards.create(:card => {:number => "4242424242424242",
:exp_month => 10, :exp_year => 2014})
#card.id #this should have the card id in it
In order to ensure consistent experience i want to set header image and business on paypal's page, view items with their names and description and ask the customer to select shipping address.
I'm using active_paypal_adaptive_payment gem (https://github.com/jpablobr/active_paypal_adaptive_payment) and the option to set_payment_options:
response = ADAPTIVE_GATEWAY.setup_purchase(
:action_type => 'CREATE',
:receiver_list => recipients,
...
)
ADAPTIVE_GATEWAY.set_payment_options(
:display_options => {
:business_name => 'Big Business',
:header_image_url => 'url goes here'
},
:sender_options => {
:require_shipping_address_selection => true },
:receiver_options => [{
:description => _description,
:invoice_data => {
:item => [{
:name => _title,
:item_count => 1,
}],
:total_shipping => 10.0,
:total_tax => 10
},
:receiver => {
:email => email
}
}])
)
The issue is that it doesn't work - i do not see any business names or image, i see generic names on the left column (the one with the items and the flow doesn't ask for shipping address).
Could you please advise?
You can also do so by logging into PayPal, then going to My Selling Tools and update the Custom payment pages option to create a new page style with the color combination and logo of your choice (there are size restrictions for the logo images)
I am making the paypal application with rails.
I have create all the necessary a/c in http://develpers.paypal.com and also have insert all that information in my rails app.
My problem is when i am trying to authorize my seller a/c, it gives me error like
"Failure: This transaction cannot be processed due to an invalid merchant configuration."
My code is:
# all inforation is of seller API id, password, signature
gateway = ActiveMerchant::Billing::PaypalGateway.new(
:login => "seller_1302505219_biz_api1.gmail.com",
:password => "...",
:signature => "..."
)
options = {
:ip => request.remote_ip,
:billing_address => {
:name => "Name",
:address1 => '1 Main St',
:address2 => '',
:city => 'San Jose',
:state => 'CA',
:country => 'US',
:zip => '95131',
# :phone => '408-983-5678'
:phone => '408-678-0945'
}
}
res = gateway.authorize(amount, credit_card, options)
You need to have a seller account set up with Website Payments Pro.
Create your selling test account using the Preconfigured option.
Under Account Type, select Website Payments Pro.
Good luck!
Got the solution.
I have google it but got the information about the "Billing agreement".
But that functionality is provided in Website Payment Pro.
so I have just create an test account using WPP and use that WPP account credential for transaction.
It works fine.
Cheers!!!
In addition, your account may or may not be enabled for Pro (DoDirectPayment) even after signing up for it in Sandbox. There's a thread on the x.com forums where you can ask one of the support guys to enable it for you.