For now, Kaching only provides kaching-paypal to accepting payment through Paypal. More strategies are under plan.
$ npm install kaching
$ npm install kaching-paypal
https://github.com/gregwym/kaching/tree/master/example
Paypal strategy require the client_id
and client_secret
offered by Paypal to operate. You can obtain them from https://developer.paypal.com/webapps/developer/applications.
It use api.sandbox.paypal.com
as the default paypal host address. Feel free to change it in production environment.
var PaypalStrategy = require('kaching-paypal');
var kaching = require('kaching');
kaching.use(new PaypalStrategy({
host: '<paypal_rest_api_endpoint>', // optional
port: '', // optional
client_id: '<paypal_client_id>',
client_secret: '<paypal_client_secret>'
}));
Use kaching.create
, specifying paypal
strategy, to create a Paypal payment. The payment detail should be setup and saved in req.payment
prior invoking the create middleware.
After kaching created the pending payment, it replaces req.payment
with the real payment object that was returned from Paypal API. Save it securely. (i.e., together with the user's order.)
app.get('...', function(req, res, next) {
// Setup payment detail in `req.payment`.
req.payment = {
amount:{
total:'7.47',
currency:'USD'
},
redirect_urls: {
return_url: 'http://<return_url>',
cancel_url: 'http://<cancel_url>'
},
description:'Kaching paypal test transaction'
};
next();
}, kaching.create('paypal', {
// Optional options
}), function(req, res) {
// Now `req.payment` is the Paypal returned payment object
res.json(req.payment);
});
For most of the time, user should redirect to Paypal to complete the payment right away. You can find the page url in payment.links
and do whatever you want.
Or simpler, append the kaching.approve
middleware after the last request handler. It will redirect the user to the payment approval page.
app.get('...', function(req, res, next) {
...
}, kaching.create('paypal', {
...
}), function(req, res, next) {
console.log(JSON.stringify(req.payment));
next();
}, kaching.approve('paypal'));
If you want to use kaching.approve
somewhere else, make sure req.payment
contain a valid payment object.
User will be redirect to return_url
once the payment has been approved. Paypal will specify the payer_id
in req.query.PayerID
. This piece of information is required to execute and complete the payment, so save it securely.
Commonly, execute the payment right after can save many trouble. Here is an example,
app.get('<return_route>', function(req, res, next) {
// Prepare payment information and payerId
req.payment = ...; // Fetch the payment object from anywhere it was saved.
req.payment.payer_id = req.query.PayerID;
next();
}, kaching.execute('paypal'), function(req, res) {
res.json(req.payment); // Now the payment has been completed.
});
Like kaching.create
, kaching.execute
will update req.payment
to the latest. And it's up to you to deal with it.
Note: all the middleware look for the payment informations in req.payment
. Make sure it is set before passing control to a middleware.
Construct a new strategy
.
var options = {
host: '<paypal_rest_api_endpoint>', // optional
port: '', // optional
client_id: '<paypal_client_id>',
client_secret: '<paypal_client_secret>'
}
Build the payment creation middleware.
It use req.payment
as the payment_detail skeleton.
req.payment = {
intent: '[sale | authorize]', // default: sale
payment_method: '[paypal | credit_card]', // default: paypal
funding_instruments: { // required when payment_method = credit_card
... // https://developer.paypal.com/webapps/developer/docs/api/#fundinginstrument-object
},
amount: { // required
... // https://developer.paypal.com/webapps/developer/docs/api/#amount-object
},
item_list: { // optional
... // https://developer.paypal.com/webapps/developer/docs/api/#itemlist-object
},
description: 'Payment description', // optional
redirect_urls: { // required when payment_method = paypal
return_url: ...,
cancel_url: ...
}
};
You may notice that, things like intent
, payment_method
and redirect_urls
are not necessarily be different for each payment. You can set the default value for them when building the middleware.
...
}, kaching.create('paypal', {
intent: 'sale',
payment_method: 'paypal',
redirect_urls: { ... }
}),
...
Then you can omit these fields in req.payment
.
Build the payment approval middleware. Mainly redirect to the approval_url
in payment.links
.
Build the approved payment execution middleware. The middleware find the payment in req.payment
and execute it with req.payment.payer_id
.
Copyright (c) 2013 Greg Wang http://gregwym.info/
]]>Remember in the Mail App, it shows update status and sending mail progress in the bottom toolbar. I think it is a really neat way to show information, especially for those apps who use native iOS UI elements.
However, I couldn't find any lib out there for this task. So I decide to invent the wheel myself.
Feel free to post any issues or patch. It's my pleasure for any who like my work.
InformaticToolbar is mainly an UIViewController Category which allows you to add several UIBarButtonItems set to your toolbar.
The sets are defined as subclasses of ITBarItemSet. All ITBarItemSet can have a dismiss button if the target and action has been defined. If more than one set has been added, a switch button (an arrow) will be displayed on the left for user to switch between sets.
For now, there are three pre-defined set:
You can easily create new sets by extending ITBarItemSet yourself.
Screenshot:
cd *your-project-location*
git submodule add git://github.com/gregwym/InformaticToolbar.git
You can either add the source codes directly or
InformaticToolbar.xcodeproj
to your project.InformaticToolbar
(the library)libInformaticToolbar.a
"${PROJECT_DIR}/InformaticToolbar/"
to User Header Search Paths, include the quotation marks.YES
-ObjC
In any UIViewController
that you want to use this lib, add #import "InformaticToolbar.h"
at the front.
Or easier, you can add the import to YOUR Prefix.pch
file.
Let's say I want to add a Label to my toolbar, I can call the following method in an UIViewController
:
- (IBAction)addLabelBarItemSet:(id)sender
{
ITLabelBarItemSet *labelBarItemSet = [ITLabelBarItemSet labelBarItemSetWithDismissTarget:self andAction:@selector(dismissBarItemSet:)];
labelBarItemSet.textLabel.text = @"This is text label. ";
labelBarItemSet.detailTextLabel.text = @"This is detail text label. ";
[self pushBarItemSet:labelBarItemSet animated:YES];
}
- (void)dismissBarItemSet:(ITBarItemSet *)sender
{
[self removeBarItemSet:sender animated:YES];
}
In the project, there is a demo app you can tryout. ITViewController.m
includes the sample usage of all three pre-defined item sets.
InformaticToolbar by Greg Wang is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
]]>这两种实现都各有利弊, 我个人倾向于ichuan的做法.
原因无外乎, 能保持Typecho文章数据的一致性, 以前存HTML现在还是存HTML, 只是编辑的方式变了.
但ichuan的插件在用的时候不是那么顺利. 因为js放置的位置好像有些问题, 编辑器和预览99%的时候加载失败(Chrome 17). 预览界面的CSS定义也有些问题.
于是自己动手丰衣足食, 把成果po出来给和我碰到同样问题的朋友们.
Mar 19/2012 v0.2.1
strong text
emphasized text
strong & emphasized text
Blockquote
enter code here
List item
一直想换主题却没有找到好的. 最近对Bootstrap很是痴迷, 又有了点空闲, 就顺手仿着Bootstrap官网风格做了一个Typecho的主题.
自己觉得效果还不错, po出来给喜欢的朋友.
下载我放在doLast.com上了, 点Download即可
http://dolast.com/pages/trapecho
https://github.com/gregwym/Trapecho/zipball/master
/admin/options-theme.php
主题设置页中填入新浪微博的UID, 侧栏中就会显示新浪微博的插件.footer.php
最后删除和pre
有关的几行JavaScript即可.使用很简单, 展示大段的代码, 使用<pre>
将代码括住, 就会自动高亮, 语言类型自动识别.
<pre>
<!--你的代码放在中间-->
</pre>
比如,
int main(){
cout << "Welcome to Trapecho" << endl;
return 0;
}
更多使用方法请参考, google-code-prettify README