I clone braintree project from https://github.com/braintree/braintree_php_example. Than I created account https://www.braintreepayments.com/sandbox. I must to return client_token. I debug this code
$result = Braintree\Transaction::sale([
'amount' => $amount,
'paymentMethodNonce' => $nonce,
'options' => [
'submitForSettlement' => true
]
]);
var_dump($result->transaction);
But token = null. Maybe my steps are incorrect?
////////////////////////////////
I did it!
I create user
$result = Braintree_Customer::create([
'firstName' => 'Mike',
'lastName' => 'Jones',
'company' => 'Jones Co.',
'email' => 'mike.jones#example.com',
'phone' => '281.330.8004',
'fax' => '419.555.1235',
'website' => 'http://example.com']);
Than I get customer_id
$result->customer->id;
Than I get token
$clientToken = Braintree_ClientToken::generate([
"customerId" => $result->customer->id
]);
Maybe problem with custom register in https://www.braintreepayments.com/sandbox.
Maybe I didn't put all information
Related
in my app the user can update the info of stripe connected account, however I ONLY want to actullay update the value of the fields that appear in the request payload, I could do this with a simple if check but the way I update the stripe array method makes this issue more complicated .
Is there any syntax sugar or trick to make this easier.
How my update method looks;
public function editConnectedAccount(Request $request)
{
$account = Account::retrieve($request->connectedAccountId);
Account::update(
$request->connectedAccountId,
[
'type' => 'custom',
'country' => 'ES',
'email' => $request->userEmail,
'business_type' => 'individual',
'tos_acceptance' => [ 'date' => Carbon::now()->timestamp, 'ip' => '83.46.154.71' ],
'individual' =>
[
'dob' => [ 'day' => $request->userDOBday, 'month' => $request->userDOBmonth, 'year' => $request->userDOByear ],
'first_name' => $request->userName,
'email' => $request->userEmail,
'phone' => $request->userPhone,
'last_name' => $request->userSurname,
//'ssn_last_4' => 7871,
'address' => [ 'city' => $request->userBusinessCity, 'line1' => $request->userBusinessAddress, 'postal_code' => $request->userBusinessZipCode, 'state' => $request->userBusinessCity ]
],
'business_profile' =>
[
'mcc' => 5812, //got it
'description' => '',
//'url' => 'https://www.youtube.com/?hl=es&gl=ES', //got it
],
'capabilities' => [
'card_payments' => ['requested' => true],
'transfers' => ['requested' => true],
],
]
);
return response()->json([
'account' => $account,
], 200);
Consider using a Form Request where you preform validation. This will neaten up your controller for a start and also make validation (never trust user input!) reusable.
Assuming validation is successful, calling $request->validated() from inside your controller method will return only the fields present and validated. You can then use either fill($request->validated()) or update($request->validated()).
I am using PayPalCheckoutSdk library following the examples, I have the following:
<?php
require __DIR__ . '/PayPalCheckout/vendor/autoload.php';
use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\SandboxEnvironment;
$clientId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$clientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$environment = new SandboxEnvironment($clientId, $clientSecret);
$client = new PayPalHttpClient($environment);
$invoiceNumber = uniqid();
$items = array();
$items[0] = [
'name' => 'HTML5',
'description' => 'Video streaming service',
'type' => 'SERVICE',
'sku' => 'sku03',
'unit_amount' =>
[
'currency_code' => 'USD',
'value' => '90.00',
],
'quantity' => '1',
'category' => 'DIGITAL_GOODS',
];
$new_item = [
'name' => 'CSS3',
'description' => 'Video streaming service',
'type' => 'SERVICE',
'sku' => 'sku02',
'unit_amount' =>
[
'currency_code' => 'USD',
'value' => '45.00',
],
'quantity' => '2',
'category' => 'DIGITAL_GOODS',
];
array_push($items , $new_item);
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
$request = new OrdersCreateRequest();
$request->prefer('return=representation');
$request->body = [
'intent' => 'CAPTURE',
'application_context' => [
'brand_name' => 'COMPANY',
'locale' => 'us-US',
'user_action' => 'PAY_NOW',
"cancel_url" => "http://localhost/PayPal/cancel.php",
"return_url" => "http://localhost/PayPal/return.php",
'landing_page' => 'BILLING',
],
'purchase_units' => [0 => [
'reference_id' => $invoiceNumber,
'amount' => [
'currency_code' => 'USD',
'value' => '160.00',
'breakdown' => [
'item_total' => [
'currency_code' => 'USD',
'value' => '180.00',
],
'shipping_discount' => [
'currency_code' => 'USD',
'value' => '20.00',
],
],
],
'items' =>
$items,
]],
];
try {
$response= $client->execute($request);
if ($response->statusCode == 201){
for ($i = 0; $i < count($response->result->links); ++$i){
$link = $response->result->links[$i];
if ($link->rel =='approve') {
header("location: $link->href");
}
}
} else {
exit(1);
}
} catch (HttpException $ex) {
echo $ex->statusCode;
print_r($ex->getMessage());
}
?>
I am receiving the data by get method print_r($_REQUEST);:
Array ( [token] => 3JX899952R0552721 [PayerID] => J95XSJRX4WXVS
And, that information is processed in the file return.php which has the following code: https://ideone.com/ncVjIt
I would like to be able to receive the information but by post method, what configurations should I make so that the data is sent by post and not by get?
As explained in comments, you can't change the redirect method back from PayPal. It will always be a GET string appended to your return_url.
However, the ideal and recommended solution is to not use any redirects. At all. Instead, use the PayPal-Checkout-SDK you have to make two routes on your server, one for 'Create Order' and one for 'Capture Order', documented here, that return only JSON data (no HTML or text). The latter one should (on success) store the payment details in your database before it does the return (particularly purchase_units[0].payments.captures[0].id, the PayPal transaction ID)
Pair these two JSON-only routes with the following approval flow that does not use any redirects, and instead keeps your site loaded in the background (lightboxed) at all times during payment approval: https://developer.paypal.com/demo/checkout/#/pattern/server
The old way of doing this was as follows
$customer = \Stripe\Customer::create(array(
"description" => $domain,
"email" => $email,
"source" => $token,
"metadata" => array(
"name" => $name,
"phone" => $phone
),
));
$cus = $customer->id;
\Stripe\Subscription::create(array(
"customer" => $cus,
"plan" => "1",
));
But now I do not see the "PLAN" option on the subscription create. Here is what I have so far...
$customer = $stripe->customers->create([
'description' => 'Description text here nomadweb.design',
'name' => 'Sammy Malones',
'email' => 'name#email.com',
'phone' => '5124592222'
]);
$cus = $customer->id;
$stripe->subscriptions->create([
'customer' => $cus,
'plan' => '1'
]);
In the API Docs is says that it's required to use the items parameter.
My question is how to I add a subscription to a customer with the newer api?
This is their code but I don't understand
$stripe->subscriptions->create([
'customer' => 'cus_J34i3JonNQQXdO',
'items' => [
['price' => 'price_0IQyZLH7HxDXZRHqJfpwwqBB'],
],
]);
https://stripe.com/docs/api/subscriptions/create
In my stripe dashboard I have a product created which is a monthly subscription, it has an ID like prod_BlMuxdEQJSxfKJ So I'm guessing I need to pass that ID in somehow as an item?
I would encourage you to read about Prices, the successor to Plans, but you can also provide an existing Plan like plan_123 to the subscription creation request, and it will be converted to a Price for you:
$stripe->subscriptions->create([
'customer' => 'cus_123',
'items' => [
['price' => 'plan_123'],
],
]);
You can't provide a Product here directly, as Products are not directly tied to any amount or interval. You need to create Prices for those Products, either using the API or your Dashboard.
When creating a subscription, you can optionally define the recurring pricing ad-hoc, using price_data (API doc) and referencing the Product to be used:
$subscription = $stripe->subscriptions->create([
'customer' => 'cus_123',
'items' => [[
'price_data' => [
'unit_amount' => 5000,
'currency' => 'usd',
'product' => 'prod_456',
'recurring' => [
'interval' => 'month',
],
],
]],
]);
Thank you to Nolan, it looks like you need to grab the product pricing API ID which is provided in the dashboard.
Here is the updated code
$stripe->subscriptions->create([
'customer' => $cid,
'items' => [['price' => 'price_0IR0OGH7HxDXZRHq3sIg9biB'],],
]);
Here the price ID is attaching the product which is a subscription to the customer.
if you are using laravel and stripe php sdk with it then you can do it like this below:
\Stripe\Stripe::setApiKey(env('STRIPE_PRIVATE_KEY'));
// Use an existing Customer ID if this is a returning customer.
// $customer = \Stripe\Customer::create([
// "description" => $domain,
// "email" => $email,
// "source" => $token,
// "metadata" => [
// "name" => $name,
// "phone" => $phone
// ],
// ]);
$customer = \Stripe\Customer::create();
// $customer_id = $customer->id;
$Subscription = \Stripe\Subscription::create([
'customer' => $customer->id,
'items' => [[
'price' => $price_id,
]],
'payment_behavior' => 'default_incomplete',
'expand' => ['latest_invoice.payment_intent'],
]);
$ephemeralKey = \Stripe\EphemeralKey::create(
['customer' => $customer->id],
['stripe_version' => '2020-08-27']
);
// $paymentIntent = \Stripe\PaymentIntent::create([
// 'amount' => $amount,
// 'currency' => $currency,
// 'customer' => $customer->id
// ]);
$response = [
'request' => $data,
'paymentIntent' => $subscription->latest_invoice->payment_intent->client_secret,
'ephemeralKey' => $ephemeralKey->secret,
'customer' => $customer->id,
'subscriptionId' => $subscription->id,
];
return response($response, 200);
And then in your front end you can process the payment with the help of your paymentIntent secret.
Using Laravel with Auth and Spatie\laravel-permission packages. I have a User with the Admin Role. Several other Permissions are also attached to this Role.
I noticed 'can:permission_name' and 'permission:permission_name' middlewares weren't functioning properly, so I started debugging. I realized that $user->getAllPermissions() only returns the permission with the highest id. In addition, when running $user->hasPermissionTo() on other permissions than the one previously mentioned, it returns false.
I would really appreciate the help. Also, I have tried to clear the cache as well.
Seeder function:
public function run() {
$permissions[0] = Permission::create(['guard_name' => 'web', 'name' => 'Access Admin Panel']);
$permissions[1] = Permission::create(['guard_name' => 'web', 'name' => 'Access Music']);
$permissions[2] = Permission::create(['guard_name' => 'web', 'name' => 'Edit Database']);
$permissions[3] = Permission::create(['guard_name' => 'web', 'name' => 'Login']);
$role[0] = Role::create(['guard_name' => 'web', 'name' => 'Administrator']);
$role[0]->permissions()->attach($permissions[0]);
$role[0]->permissions()->attach($permissions[1]);
$role[0]->permissions()->attach($permissions[2]);
$role[0]->permissions()->attach($permissions[3]);
$role[1] = Role::create(['guard_name' => 'web', 'name' => 'VIP']);
$role[1]->permissions()->attach($permissions[1]);
$role[1]->permissions()->attach($permissions[2]);
$role[1]->permissions()->attach($permissions[3]);
$role[2] = Role::create(['guard_name' => 'web', 'name' => 'Trusted']);
$role[2]->permissions()->attach($permissions[2]);
$role[2]->permissions()->attach($permissions[3]);
$role[3] = Role::create(['guard_name' => 'web', 'name' => 'User']);
$role[3]->permissions()->attach($permissions[3]);
$role[4] = Role::create(['guard_name' => 'web', 'name' => 'Disabled']);
$admin = User::create(['name' => 'Gandalfsdottir', 'email' => 'my#email.com', 'password' => Hash::make('demo')]);
$admin->markEmailAsVerified();
$admin->assignRole('Administrator');
$demo = User::create(['name' => 'Demo', 'email' => 'my#secondemail.fr', 'password' => Hash::make('demo')]);
$demo->markEmailAsVerified();
$demo->assignRole('User');
}
I am runing a bitcoin investment website. I want to give user free bonus of 0.005 points on registration. I have tried following in my registration Controller to fill database table. It works perfectly but after 100 user it creat some type of bug and I get error in user login it says:
But I remove all rows of depostit table all functions work perfectly.
trying to get property of non object
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'under_reference' => $data['reference'],
'password' => bcrypt($data['password']),
'verifyToken' => Str::random(40),
'reference' => Str::random(12),
'status' => $status,
'image' => $image25
]);
$deposit = Deposit::create([
'deposit_number' => date('ymd').Str::random(6).rand(11,99),
'user_id' => $user->id,
'plan_id' => "7",
'percent' => "1",
'time' => "30",
'compound_id' => "2",
'amount' => "0.005",
'status' => "0"
]);