I am using this:
$sell = new Sell([
'bitcoinAmount' => (-1*$buyAmount)
]);
$client->createAccountSell($account, $sell);
But it is sending my money to my bank account and initiating a wire transfer. How can I make it so it sends the money to my USD Wallet?
I had to do this:
$sell = new Sell([
'bitcoinAmount' => .002,
'paymentMethodID' => $usdWalletID
]);
$client->createAccountSell($account, $sell);
Related
I use https://github.com/coinbase/coinbase-php with laravel to send Eth from my wallet to wallet on other service.
I use this method: $client->createAccountTransaction($account, $transaction);
In this way:
$transaction = Transaction::send([
'to' => new EthrereumAddress($destination_address),
'amount' => new Money($amount, $currency),
'description' => $description,
//'fee' => '0.0001' // only required for transactions under BTC0.0001
]);
$this->client->createAccountTransaction($account, $transaction);
But when I try to do this, I get this error:
The Coinbase API only accepts transactions to an account, email, or bitcoin address
Can someone tell me how to send eth or what is wrong ?
This was fixed in the latest 2.8.0 version.
https://github.com/coinbase/coinbase-php/releases/tag/2.8.0
You should use right $account for each cryptocurrency, but not just the $client->getPrimaryAccount();
For example:
$account = Account::reference('YOUR_ETH_ACCOUNT_ID');
I am struggling for this for two days, I want to differentiate between subscription assignment and manually deducting the charge from Stripe. charge.succeeded webhook is called both times. In webhook call, I need to differentiate between Subscription assignment and Charge deduction for a particular amount.
Subscription Assignment is using below code.
$subscription = \Stripe\Subscription::create(array(
"customer" => $customer_id,
"plan" => $stripe_plan_id,
));
And charge deduction is using below code.
$charge = \Stripe\Charge::create(array(
'amount' => $price ,
'currency' => 'usd',
'customer' => $customer_id
)
);
If anyone has any idea please suggest the way. Thank you !!
Upon receiving the charge.succeeded event, you can extract the charge object and check the charge's invoice attribute:
// Retrieve the request's body and parse it as JSON
$input = #file_get_contents("php://input");
$event_json = json_decode($input);
if ($event_json->type == "charge.succeeded") {
$charge = $event_json->data->object;
if ($charge->invoice == null) {
// One-off charge
} else {
// Subscription charge
}
}
Note that technically, a charge can be linked to an invoice but not to a subscription, in case you created an invoice manually. If you need to distinguish in this case, you'll need to use the invoice's ID to retrieve the invoice, and check the invoice's subscription attribute to see if it's null or not.
I'm using Stripe Payments and would like to give customers the possibility to change their credit card. Referring to https://stripe.com/docs/api#create_subscription -> source, I tried the following PHP-code:
$customer = \Stripe\Customer::retrieve($client_id);
$customer = \Stripe\Customer::create(array(
"source" => $token) //the token contains credit card details
);
This works, but unfortunately it unintentionally also creates a new customer ID:
The original customer ID was cus_6elZAJHMELXkKI and I would like to keep it.
Does anybody know the PHP-code that would update the card without creating a new customer?
Thank you very much in advance!
PS: Just in case you need it – this was the code that originally
created the customer and the subscription:
$customer = \Stripe\Customer::create(array(
"source" => $token,
"description" => "{$fn} {$ln}",
"email" => $e,
"plan" => "basic_plan_id")
);
\Stripe\Charge::create(array(
"amount" => 10000, # amount in cents, again
"currency" => "eur",
"customer" => $customer->id)
);
I've just found the answer, maybe it helps someone of you, too:
You can replace the old card with the new one like so:
$customer = \Stripe\Customer::retrieve($client_id);
$new_card = $customer->sources->create(array("source" => $token));
$customer->default_source = $new_card->id;
$customer->save();
The answer helped a bunch but commenter was correct that old card wasn't deleted.
Assuming you would only ever have one card for a customer you would do this instead:
//get customer
$customer = \Stripe\Customer::retrieve($client_id);
//get the only card's ID
$card_id=$customer->sources->data[0]->id;
//delete the card if it exists
if ($card_id) $customer->sources->retrieve($card_id)->delete();
//add new card
$new_card = $customer->sources->create(array("source" => $token));
$customer->default_source = $new_card->id;
$customer->save();
I want to get the last 4 digits of a customers card using Stripe.
I have already stored the Customer using:
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
// Create a Customer
$StripeCustomer = \Stripe\Customer::create(array(
"description" => "$username",
"card" => $token
));
Now I'd like to access and then store the card's last 4 digits. (For context, I want to show users which card they have stored using Stripe for future payments - this is not a subscription service).
I have searched for a solution but a lot of the posts are saving the last4 digits AFTER a charge, and pull the information from the charge like:
$last4 = null;
try {
$charge = Stripe_Charge::create(array(
"amount" => $grandTotal, // amount in cents, again
"currency" => "usd",
"card" => $token,
"description" => "Candy Kingdom Order")
);
$last4 = $charge->card->last4;
I would like to do the same BEFORE the charge , so I want to pull the last 4 from the Customer Object. The Stripe API documentation shows the attribute path for last4 from Customers,
customer->sources->data->last4
However, this does not seem to give me the correct last 4 digits.
$last4 = $StripeCustomer->sources->data->last4;
I think I am misunderstanding how to use attributes in the Stripe API. Could someone point me in the right direction?
$last4 = $StripeCustomer->sources->data[0]->last4;
sources->data is an array so you'd have to select the first card.
Side note: You're using the token twice, once to create the customer, and the second to create the charge, this will result in an error as the token can only be used once. You'd have to charge the customer instead of the token.
For any one else who lands here from search engines, here's a link to the Stripe docs on how to get the last 4 digits of a card saved to the customer https://stripe.com/docs/api/customers/object#customer_object-sources-data-last4
If you use Laravel Cashier, this code will be helpful for you.
$data = User::find(auth()->user()->id);
$payment = $data->defaultPaymentMethod();
$last4 = $payment->last4;
$brand = $payment->brand;
dd($payment);
You can get all information from this object.
This API has changed since this was first answered. For API version 2020-08-27 you need to use the ListPaymentsMethod API on the Customer object.
The path to access via JSON would look like this
$paymentMethods = $stripe->paymentMethods->all([
'customer' => 'cus_123',
'type' => 'card',
]);
$last4 = $paymentMethods->data[0]->card->last4
I have used the Omnipay PayPal_Express checkout script on my site and everything works fine when I pay for an order except the order doesn't show in the PayPal Sandbox account.
It does show when I use the same script for PayPal_Pro.
My code is as follows:
use Omnipay\Omnipay;
// PayPal Express:
if(isset($_POST['paypalexpress'])) {
$gateway = GatewayFactory::create('PayPal_Express');
$gateway->setUsername('{myusername}');
$gateway->setPassword('{mypassword}');
$gateway->setSignature('{mysignauture}');
$gateway->setTestMode(true);
$response = $gateway->purchase(
array(
'cancelUrl'=>'http://www.mysite.com/?cancelled',
'returnUrl'=>'http://www.mysite.com/?success',
'amount' => "12.99",
'currency' => 'GBP',
'Description' => 'Test Purchase for 12.99'
)
)->send();
$response->redirect();
}
I have created two test accounts in my Sandbox, one is for the above API and one I use to pay with. I have tried paying with the test card details and the login but the order detail doesn't show in the account.
Can anyone help?
It looks like you're missing the completePurchase() part when Paypal returns to your returnUrl. My code assumes that you have the order details in a variable $order, but it may look something like this:
if(isset($_GET['success'])) {
$response = $gateway->completePurchase(array(
'transactionId' => $order->transaction,
'transactionReference' => $order->reference,
'amount' => $order->total,
'currency' => $order->currency,
))->send();
if ( ! $response->isSuccessful())
{
throw new Exception($response->getMessage());
}
}
Let me know if you need any help retrieving the order details on return. It can be stored in a session before you redirect, or in a database. If you haven't done already, take a look at the example code: https://github.com/omnipay/example/blob/master/index.php