Braintree: What is paymentMethodToken required in creating subscriptions? - braintree

https://developer.paypal.com/braintree/docs/guides/recurring-billing/create
result = Braintree_Subscription::create(array(
'paymentMethodToken' => 'the_token',
'planId' => 'silver_plan'
));
Is it a random generated string in my code? Or is it something else?

The paymentMethodToken is a unique identifier for the customer's credit card to use. After you create a Customer with a stored payment method you can use the returned token to subscribe a user to a plan. This article explains it well:
https://developer.paypal.com/braintree/docs/guides/recurring-billing/overview

Related

Get list of shipping methods for a subsidiary

I'm using NetSweet/NetSuite Ruby gem for connecting to NetSuite accounts.
Normally it's trivial to get list of shipping methods using get_select_value. However one NetSuite account is organized into subsidiaries, and shipping methods are assigned to subsidiaries. For this particular account, get_select_value returns empty list:
NetSuite::Records::BaseRefList.get_select_value({
recordType: "salesOrder",
field: "shipMethod",
}).base_refs.length
=> 0
This makes some sense: in new sales order form the list of shipping methods is initially empty. When I select "customer" option, NetSuite automatically fills the read-only field "subsidiary". Then list of available shipping methods is populated.
Is there a way to fetch list of shipping methods by subsidiary or for a customer?
NetSuite API response contains a warning: "Results are incomplete. You must provide a value for field entity."
Full response:
<getSelectValueResponse xmlns="urn:messages_2016_2.platform.webservices.netsuite.com">
<platformCore:getSelectValueResult xmlns:platformCore="urn:core_2016_2.platform.webservices.netsuite.com">
<platformCore:status isSuccess="true">
<platformCore:statusDetail type="WARN">
<platformCore:code>WARNING</platformCore:code>
<platformCore:message>Results are incomplete. You must provide a value for field entity.</platformCore:message>
</platformCore:statusDetail>
</platformCore:status>
<platformCore:totalRecords>0</platformCore:totalRecords>
<platformCore:totalPages>0</platformCore:totalPages>
</platformCore:getSelectValueResult>
</getSelectValueResponse>
Using filterByValueList and passing customer internalId as entity seems to work.
NetSuite::Records::BaseRefList.get_select_value({
recordType: "salesOrder",
field: "shipMethod",
filterByValueList: {
"platformCore:filterBy" => {
"platformCore:field" => "entity",
"platformCore:internalId" => ns_customer.internal_id}
}
}).base_refs.length
=> 17
It's somewhat counter-intuitive, as filter option should reduce items in the output.
Generated XML:
<platformMsgs:getSelectValue>
<platformMsgs:pageIndex>1</platformMsgs:pageIndex>
<platformMsgs:fieldDescription>
<platformCore:recordType>salesOrder</platformCore:recordType>
<platformCore:field>shipMethod</platformCore:field>
<platformCore:filterByValueList>
<platformCore:filterBy>
<platformCore:field>entity</platformCore:field>
<platformCore:internalId>4978501</platformCore:internalId>
</platformCore:filterBy>
</platformCore:filterByValueList>
</platformMsgs:fieldDescription>
</platformMsgs:getSelectValue>

Getting Stripe Upcoming Invoice Line Items with Laravel Cashier

I'm attempting to use Laravel Cashier to retrieve line items of the client's upcoming invoice. I'm having difficulty obtaining the invoice in the first place. Though I've found the undocumented public function "upcomingInvoice," I can't get any of its protected properties out.
Even with it, I'm having trouble understanding how to use the poorly documented "asStripe..." functions, presumably asStripeInovice(), to return the line items.
I've tried a whole host of things and it would muddle things up to write them all out, so I figure it might be better just to ask how to go about it.
Thanks!
Try this one liner code in laravel 7 or 8 with cashier.
$user->upcomingInvoice()
And you're good getting all upcoming invoices details.
As up update, I was able to get this to work just using the Stripe client, like so:
$stripe = new StripeClient(env('STRIPE_SECRET'));
$upcomingLineItems = $stripe->invoices
->upcomingLines(['customer' => $customer['stripe_id']]);
I'll still leave this open in case there's a way to do it with Cashier's methods, but it now doesn't seem necessary.
Similarly, I wanted to be able to display the "amount due today" to a user prior to switching subscription plans (which takes into account proration as well as any credit applied to the customer's account). I was able to do this in Laravel using the following:
$stripe_client = new StripeClient(config('stripe.secret'));
$items = [
[
'id' => $user->subscription()->items()->first()->stripe_id,
'price' => $selected_plan, # Switch to new price
],
];
$invoice = $stripe_client->invoices->upcoming([
'customer' => $user->stripe_id,
'subscription' => $user->subscription()->stripe_id,
'subscription_items' => $items,
'subscription_proration_date' => Carbon::now()->timestamp
]);
$amount_due = $invoice->amount_due; // and there it is

add catalog item and category to purchase via transactions api

Im using payment form and square transaction api to retrieve payment but it's showing up uncategorized in square dashboard. Is there an easy way to add the catalog item to the transaction api code i've already written?
can i simply add the link to the new order item under the request_body array?
$request_body = array (
"card_nonce" => $nonce,
)
$txRequest['item_id'] = "my item id";
If anyone has a tutorial that would be much appreciated.
I figured it out.
I had to create and Order with the orders api, then pass the order_id to the charge code. In php it looks like this.
.......create order here using orders api(code not shown)......
...pass order_id to charge(in php)...
mix of variables for nonce, etc...
............
$request_body = array (
"card_nonce" => $nonce,
"buyer_email_address" => $be,
"note" => "online Laser Tag reservation",
"amount_money" => array (
"amount" => $totalCost,
"currency" => "USD")
"order_id" => $my_order_id,
"idempotency_key" => uniqid()
};
...try/catch statements...
You'll want to use CreateOrder to create an order of items. Then you can pass in the order_id to the Transactions API (what you will use after the payment form to call the Charge endpoint). See here: https://docs.connect.squareup.com/payments/transactions/cookbook/itemize-transactions

mailchimp api delete user from list

when user unsubscribes from list he can't subscribe again with the same email address. How can allow user to resubscribe to list?
$unsubscribe = $mailChimp->call('lists/unsubscribe',array(
'id' => $list_id,
'email' => array('email' => $email),
true,
true
));
If you want to resubscribe the user later, you need to delete him, see the documentation:
When you need to remove a few subscribers, decide whether you want to delete
them yourself or unsubscribe them. Deleted subscribers can be added
back to your list, so if you need to make sure a subscriber isn't
accidentally re-added, unsubscribe them instead.
If you are using the latest mailchimp-api then you can delete the user as follows:
include 'Mailchimp.php';
use \DrewM\MailChimp\MailChimp;
$MailChimp = new MailChimp('your**api***key');
function deleteUser($email){
global $MailChimp;
//your list_id from Mailchimp
$list_id = 'your***list**id';
$subscriber_hash = $MailChimp->subscriberHash($email);
$MailChimp->delete("lists/$list_id/members/$subscriber_hash");
}
If no user with that email exists, then $MailChimp->delete() will return an array like this:
Array ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Resource Not Found [status] => 404 [detail] => The requested resource could not be found. [instance] => )
If the user was found, then the method will not return anything. Note that this does not imply that the user has been deleted, because if the user has been unsubscribed previously, then its not possible to delete him.
If you do not want to use the api, then you can also write your own custom curl command using the delete verb.
Try deleting the email from list and re-subscribe the same.
You can delete the member by setting delete_member property to true in unsubscribe method
You can do it by updating the user to a status of "pending"
Unfortunately my code is the Python api, but you should be able get the idea.
def mcResendSubscriptionSignup(self,email,audienceId):
# calculate the hash of the email address
emailHash = hashlib.md5(email.lower().encode()).hexdigest()
# get existing user, and all their data
data = self.mcClient.lists.members.get(list_id=audienceId, subscriber_hash=emailHash)
# set the user status to pending to resend subscription email
data['status'] = 'pending'
# update the data back to the user record in the audience
data = self.mcClient.lists.members.update(list_id=audienceId, subscriber_hash=emailHash, data=data)
print(f'Sent a resubscription email to {email}')
This function will resend a confirmation email to the user which he has to click on to resubscribe. Note, you need to also find your audienceId.
This is the only way that Mailchimp will allow you to re-add the user to an audience as of 2020, after an unsubscribe.
Yes, this is a pain when testing, which is why I worked on this function. Tiny bit better than doing it in the GUI interface.

How to validate variable in Symfony 1.4

I use Symfony 1.4.11. I have two tables "companies" and "ads". When user add new ad, he can connect ad with his company.Before it I check, if user have company, for example I have variable $has_company, if $has_company==1 - user has company, if $has_company==0 he has not company. If user want connect company with ad, he must check checkbox :-) So I want to validate checkbox, If user check checkbox, and he has not company,I want to show messages, that first he must create company.... Is it possible? Can I use sfValidatorBoolean ? If yes, how to validate variable has_company? Thank you!
I think you can create a method in myUser class to check if the current user has a company (if your models user and company are linked).
And then, you can pass the result of this method in option of your form.
For validation, you can use a callback validator : http://www.symfony-project.org/forms/1_4/en/B-Validators#chapter_b_sub_sfvalidatorcallback
you can use halt_on_error option like
$v = new sfValidatorAnd(
array(
new sfValidatorString(array('max_length' => 255)),
new sfValidatorEmail(),
),
array('halt_on_error' => true),
array('invalid' => 'The input value must be an email with less than 255 characters.')
);

Resources